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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no 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!feeder1-2.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: About String Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <484ABED3.8040909@obry.net> <484b802a$0$23844$4f793bc4@news.tdc.fi> Date: Sun, 15 Jun 2008 22:52:45 +0200 Message-ID: <12uzegqkwihil.gi8iceyncrph.dlg@40tude.net> NNTP-Posting-Date: 15 Jun 2008 22:52:47 CEST NNTP-Posting-Host: 90199c8e.newsspool1.arcor-online.net X-Trace: DXC=KHWfi`eoCI^f\Y]Eaic==]BZ:afn4Fo<]lROoRa<`=YMgDjhgb5g[:TIVW\Ub[6LHn;2LCVn[ 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." 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. > 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; --------------- What I miss is things like: 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; -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de