From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,dbbbb21ed7f581b X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!feeder.news-service.com!feeder.news-service.com!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Tue, 01 Dec 2009 16:02:21 +0100 From: Georg Bauhaus User-Agent: Thunderbird 2.0.0.23 (Macintosh/20090812) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Operation can be dispatching in only one type References: <025105f2-5571-400e-a66f-ef1c3dc9ef32@g27g2000yqn.googlegroups.com> <1iipp3bn16fe2.yqa1gz1ru17a$.dlg@40tude.net> <18wh86jvjvoe0.cofxcc8udm6q$.dlg@40tude.net> <53a35ed9-88ac-43dc-b2a2-8d6880802328@j19g2000yqk.googlegroups.com> <4b091fb9$0$6567$9b4e6d93@newsspool4.arcor-online.net> <1w0q3zxzw79pt$.5z0juiky7kfd$.dlg@40tude.net> <0f177771-381e-493b-92bb-28419dfbe4e6@k19g2000yqc.googlegroups.com> <1nbcfi99y0fkg.1h5ox2lj73okx$.dlg@40tude.net> <59acf311-3a4a-4eda-95a3-22272842305e@m16g2000yqc.googlegroups.com> <4b150869$0$6732$9b4e6d93@newsspool2.arcor-online.net> <18vlg095bomhd.8bp1o9yysctg$.dlg@40tude.net> In-Reply-To: <18vlg095bomhd.8bp1o9yysctg$.dlg@40tude.net> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Message-ID: <4b152ffe$0$7615$9b4e6d93@newsspool1.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 01 Dec 2009 16:02:22 CET NNTP-Posting-Host: ca2feac7.newsspool1.arcor-online.net X-Trace: DXC=g>LUHW7152XaAeROF2PWMQic==]BZ:af^4Fo<]lROoRQ<`=YMgDjhgRnDOROYlK6_Pnc\616M64>ZLh>_cHTX3j]6a2fc;@n[PS X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:8269 Date: 2009-12-01T16:02:22+01:00 List-Id: Dmitry A. Kazakov schrieb: > On Tue, 01 Dec 2009 13:13:29 +0100, Georg Bauhaus wrote: > >> Then we could rely on the language: compilers will detect >> uninitialized variables provided these do not have a pragma/keyword/... >> to say that uninitialized is what the programmer wants. >> Some fancy means to tell the compiler that this variable >> does indeed have a good first value like pragma Import. >> >> X : [constant] Car; -- default init, > > The error is here! >> -- undefined, >> -- junk bits. Doesn't matter >> -- *no* pragma Import (Ada, X); >> >> begin >> >> Spare := X.Tire (5); -- would become illegal, > > Not here! Why? Nothing needs to have happened in between the X's declaration and the first reference made to it. > ------------------------- > Anyway, you cannot do that because: > > if HALT (P) then > X := Z; > end if; > Y := X; -- Is this legal? (HALT is a run-time issue that has no impact here.) While this snippet would not be legal as is (on purpose!), Ada's case coverage rules can make the programmer write a legal program easily: write an else branch! The compiler can then decide that a value will be assigned in either branch. If nothing is to be assigned this can only be for the reason that the variable is imported, or has a value already. In the former case an unchecked conversion involving only the variable will do; syntactic sugar might be nice to have. if HALT (P) then X := Z; else !X; end if; One might even omit the else branch without loss when Ada forces saying that the variable is imported. >> Does the phrase "first value" make sense? > > An object shall not have invalid values. All values are valid if the > language is typed. Enforcing user-defined construction including > prohibition of certain kinds of construction (e.g. per default constructor) > is a different story. > If you feed this to a Java compiler you will see how it is done. The Java compiler will not accept a reference to a variable's component when the variable may not have been initialized. import java.math.BigInteger; public class Dummy { enum TireColor { Black, White }; class Tire { TireColor rim_color; } public static void main(String[] args) { Tire spare; TireColor its_color; final BigInteger P; // some program's number P = BigInteger.valueOf(Long.parseLong(args[0])); if (HALT(P)) { spare = new Tire(); } // this line not accepted by a Java compiler: its_color = spare.rim_color; // <----- } static boolean HALT(BigInteger gn) { // dummy if (gn.equals(BigInteger.ZERO)) return true; return HALT(gn.add(BigInteger.ONE)); } }