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: 103376,5af5c381381ac5a7 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!feeder.news-service.com!85.214.198.2.MISMATCH!eternal-september.org!.POSTED!not-for-mail From: "Alex R. Mosteo" Newsgroups: comp.lang.ada Subject: Re: Ada requires too much typing! Followup-To: comp.lang.ada Date: Thu, 10 Jun 2010 15:58:37 +0200 Organization: A noiseless patient Spider Message-ID: References: <876j8vF54kU1@mid.individual.net> <4c0e2af7$0$7659$9b4e6d93@newsspool1.arcor-online.net> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit Injection-Date: Thu, 10 Jun 2010 13:58:36 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="w8g++bW4v3KH0+SqtoCNSw"; logging-data="8148"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18fR37bOYGsUcGf9PYxIEj5" User-Agent: KNode/4.4.3 Cancel-Lock: sha1:Pb9W6ZEHGhkSPXgy5WuDA19qV+k= Xref: g2news1.google.com comp.lang.ada:11594 Date: 2010-06-10T15:58:37+02:00 List-Id: Georg Bauhaus wrote: > On 08.06.10 12:10, Niklas Holsti wrote: >> Martin Krischik wrote: >> >>> just about as painful as using local packages to add static variables >>> to Ada procedures. >> >> Later Martin Krischik wrote: >> >>> function f returns Integer >>> >>> package i is >>> g : Integer := 0; >>> end i; >>> >>> begin >>> i.g := i.g + 1; >>> return i.g; >>> end f; >> >> If you mean the latter code to be an example of the former task (add >> static variable), I believe you are mistaken. > > I thought, too, that a new variable decl inside the local package > would still be elaborated each time. The initilization of g > confirms when tested. > > But then I thought, surprise!, doubted everything I thought > I had learned about Ada. Looking at this: > > with Ada.Text_IO; use Ada.Text_IO; > > procedure Sttc is > > type T is range 0 .. 10; > > procedure A is > package P is -- local package > V: T; -- presumably static? > end P; > begin > if P.V'Valid then > P.V := P.V + 1; > else > P.V := T'First; > end if; > Put_Line (T'Image(P.V)); > end A; > > begin > A; A; A; > end Sttc; > > > $ ./sttc > 0 > 1 > 2 > 3 > $ > > Compiled with or without -gnatVa. But this seems to be accidental, > V is just a variable that isn't initialized, living on the stack. > Confirmation: > > with Ada.Text_IO; use Ada.Text_IO; > > procedure Sttc is > > type T is range 0 .. 10; > > procedure A is > package P is > V: T; > end P; > begin > if P.V'Valid then > P.V := P.V + 1; > else > P.V := T'First; > end if; > Put_Line (T'Image(P.V)); > end A; > > procedure Ovrwrt_Stk is > X : T; > begin > X := T'First; > end Ovrwrt_Stk; > > begin > A; Ovrwrt_Stk; A; Ovrwrt_Stk; A; Ovrwrt_Stk; A; > end Sttc; > > $ ./sttc > 0 > 1 > 1 > 1 > $ > > Phew. Back to normal. Hehehe here too :) Nice example BTW with the stack.