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,86c750b8474bf6d5 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: About String Date: Sun, 15 Jun 2008 18:06:00 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <484ABED3.8040909@obry.net> <484b802a$0$23844$4f793bc4@news.tdc.fi> <12uzegqkwihil.gi8iceyncrph.dlg@40tude.net> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls6.std.com 1213567560 4279 192.74.137.71 (15 Jun 2008 22:06:00 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Sun, 15 Jun 2008 22:06:00 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:KIWFxH+IWJe+VfdAglTRvbhtTys= Xref: g2news1.google.com comp.lang.ada:721 Date: 2008-06-15T18:06:00-04:00 List-Id: "Dmitry A. Kazakov" writes: > On Sun, 15 Jun 2008 15:38:08 -0400, Robert A Duff wrote: > >> "Dmitry A. Kazakov" writes: >> >>> On Sun, 08 Jun 2008 17:19:11 -0400, Robert A Duff wrote: >>> >>>> I agree. I suppose it comes from Pascal, where declarations and >>>> executable code are completely separated. It makes no sense in >>>> Ada, where declarations are just as executable as statements. >>> >>> I disagree. I think it does make sense because it clearly defines the scope >>> of the declared variable. Expression (result) /= named object. And >>> reversely, if you don't need the variable, you are free to put expressions >>> anywhere outside the declaration part. >> >> If Ada allowed: >> >> for I in A'Range loop >> X : constant Character := F(A(I)); -- Not Ada! >> Do_Something(X); >> end loop; >> >> the scope of X is clear -- it's the entire loop body. > > No, then it should better be something like: > > for I in A'Range; > X : constant Character := F(A(I)); -- Not Ada! > loop > Do_Something(X); > end loop; > > The declarative part of a loop is between "for" and "loop." I don't see why a loop needs a declarative part. My idea is that every statement list is a scope. > However I find nested declare/begin/end more readable because it clearly > disambiguates between the scope of the loop and the scope of one iteration > of. I don't get it. You declare something inside a loop body, or the 'then' part of an 'if' -- it's local to that. >> You could still say: >> >> for I in A'Range loop >> begin >> X : constant Character := F(A(I)); -- Not Ada! >> Do_Something(X); >> end; >> Do_Something_Else; >> end loop; > > But what would happen if I said: > > begin > raise Foo_Error; > X : constant Character := F(A(I)); -- Not Ada! > Do_Something (X); > exception > when Foo_Error => > Do_Something_Interesting (X); > end; As I said earlier, exception-handler regions deserve their own syntax, not connected with declaration blocks. > --------------- > What I miss is things like: Not sure how these are related to local decls... > procedure Foo (X : T'Class) is > begin > case X is > when S_X : S'Class => > Do_S_Method (S_X); > when others => > Do_Something_Else; > end case; > end Foo; > > procedure Bar (Ptr : access T'Class) is > begin > case Ptr is > when Ref : not null access T => > Ref.Foo; -- No more checks > when others => > null; > end case; > end Bar; > > case I is > when Checked_I : A'Range => > ... A (Checked_I) ... -- No range checks > ... > end case; > > case L - 123 is > when Sum : Positive => > -- Sum = L - 123 and it is positive > ... > when Sum : Integer => > -- Sum = L - 123 and it is not positive > ... > when others => > -- It would overflow, but no exception was propagated > ... > end case; - Bob