From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: About String
Date: Sun, 15 Jun 2008 18:06:00 -0400
Date: 2008-06-15T18:06:00-04:00 [thread overview]
Message-ID: <wcczlpm1hh3.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: 12uzegqkwihil.gi8iceyncrph.dlg@40tude.net
"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
> On Sun, 15 Jun 2008 15:38:08 -0400, Robert A Duff wrote:
>
>> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> 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
next prev parent reply other threads:[~2008-06-15 22:06 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-06 17:29 About String Sébastien Morand
2008-06-07 16:18 ` Simon Wright
2008-06-07 17:01 ` Pascal Obry
2008-06-07 22:13 ` Chris Moore
2008-06-08 6:47 ` Niklas Holsti
2008-06-08 7:35 ` Dmitry A. Kazakov
2008-06-08 10:29 ` Sebastien Morand
2008-06-08 10:53 ` Dmitry A. Kazakov
2008-06-08 11:14 ` Niklas Holsti
2008-06-08 13:16 ` Dmitry A. Kazakov
2008-06-08 17:17 ` Niklas Holsti
2008-06-09 7:26 ` Dmitry A. Kazakov
2008-06-08 11:48 ` Martin
2008-06-08 13:17 ` Conditional declarations (was: About String) Dmitry A. Kazakov
2008-06-08 18:26 ` About String Chris Moore
2008-06-08 18:32 ` Robert A Duff
2008-06-08 20:51 ` Maciej Sobczak
2008-06-08 21:19 ` Robert A Duff
2008-06-09 7:14 ` Dmitry A. Kazakov
2008-06-09 9:43 ` Georg Bauhaus
2008-06-09 10:25 ` Dmitry A. Kazakov
2008-06-09 10:42 ` Sébastien Morand
2008-06-09 11:43 ` Georg Bauhaus
2008-06-09 12:03 ` Dmitry A. Kazakov
2008-06-15 19:38 ` Robert A Duff
2008-06-15 20:52 ` Dmitry A. Kazakov
2008-06-15 22:06 ` Robert A Duff [this message]
2008-06-16 8:31 ` Dmitry A. Kazakov
2008-06-16 19:17 ` Robert A Duff
2008-06-16 20:30 ` Dmitry A. Kazakov
2008-06-16 22:02 ` Georg Bauhaus
2008-06-16 23:04 ` Robert A Duff
2008-06-09 11:00 ` Georg Bauhaus
2008-06-09 14:27 ` Britt Snodgrass
2008-06-15 19:50 ` Robert A Duff
2008-06-15 19:48 ` Robert A Duff
2008-06-08 11:13 ` Simon Wright
2008-06-08 19:03 ` Sebastien Morand
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox