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!news3.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad01.newshosting.com!newshosting.com!198.186.194.249.MISMATCH!transit3.readnews.com!news-xxxfer.readnews.com!news-out.readnews.com!transit4.readnews.com!panix!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: About String Date: Mon, 16 Jun 2008 15:17:15 -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> <1v6vlmvr3u3dj.qtfnfe9fmxjm.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 1213643835 23830 192.74.137.71 (16 Jun 2008 19:17:15 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Mon, 16 Jun 2008 19:17:15 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:bGdj4ZT5bkaXvy6HnzK+tK67HW4= Xref: g2news1.google.com comp.lang.ada:726 Date: 2008-06-16T15:17:15-04:00 List-Id: "Dmitry A. Kazakov" writes: > On Sun, 15 Jun 2008 18:06:00 -0400, Robert A Duff wrote: > >> I don't see why a loop needs a declarative part. >> My idea is that every statement list is a scope. > > What is so special in statement lists? Pushing this idea further, we should > also conclude that any sequence of expressions is a scope. For example, an > aggregate: > > String'(X : constant Character := F(A(I)), 1 => X, 2 => 'a', 3 => X); > > a function call etc. Well, I suppose something like that could work, but it seems like it would be confusing -- how many components are there, which pieces of text belong to which components (or which parameters, in the function call case)? > [ That might be useful to overcome some silly limitations on discriminants: > > type T (S : Storage_Count) is record > -- Buffer : Storage_Elements_Array (0..S-1); -- This would be illegal, so > Buffer : Storage_Elements_Array > (Last : constant Storage_Offset := S-1, 0..Last); > end record; ] I don't see the point. Why not just make it legal (the line marked "This would be illegal"). Rules would be needed about when to evaluate that expression -- presumably on elaboration of a discriminant constraint, or an aggregate, or a discriminant default. I don't think having a name for Last makes this any easier. >>> 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. > > Local in which sense? There are statical nesting and dynamic execution of > the loop body upon iterations. The same sense as declare blocks. That is, in my "circus", this: ... loop end loop; has identical semantics to: ... loop declare begin end; end loop; The are elaborated each time through the loop. (I can't imagine what _else_ it might mean!) >...It is not obvious (rather counterintuitive) > that declarations have to be "executed." Well, it's a fundamental aspect of Ada, so Ada programmers have to get used to it, even if they find it counterintuitive at first. >...To me the purpose of Ada's > "declare" was merely in conversion of "elaboration" to "execution." > >>> 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. > > So an exception handler attached to the statement list will see nothing > from the scope of the list? I.e. everything in the list will be wound up > before the handler gets fired. Then you would need additional nesting if > you wished to handle exceptions from that list. Here we go: > > X : constant ...; > Y : constant ...; > begin > Do_Something (X, Y); > exception > when Foo_Error => > Do_Something_Interesting (X, Y); > end; > > What is the gain? Just add "declare" in front of this and it becomes legal > Ada. That's where this conversation started: If you add "declare" above, you get confusing syntax -- it looks like the exception handler handles exceptions during the elab of X and Y, but it does not. That's why I think it would be better to have a separate "handle" statement. - Bob