comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: About String
Date: Mon, 16 Jun 2008 22:30:12 +0200
Date: 2008-06-16T22:30:13+02:00	[thread overview]
Message-ID: <5214921yiqbr$.1vxzfd0p606q7.dlg@40tude.net> (raw)
In-Reply-To: wcc4p7txk90.fsf@shell01.TheWorld.com

On Mon, 16 Jun 2008 15:17:15 -0400, Robert A Duff wrote:

> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> 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)?

Right, and to me declarations intermixed with statements look similarly
confusing.

>> [ 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").

Well, maybe because it wasn't made since 1983? (:-))

> 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.

It would be a "big" change and with it small ones could also get through...
(:-))

>>>> 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
>         <decls>
>         <statements>
>     end loop;
> 
> has identical semantics to:
> 
>     ... loop
>         declare
>             <decls>
>         begin
>             <statements>
>         end;
>     end loop;
> 
> The <decls> are elaborated each time through the loop.
> (I can't imagine what _else_ it might mean!)

An invariant elaborated once for all iterations.

The mental block people like me have is that declarations are neither
statements nor operators. So an iteration does not iterate declarations. Or
better to say, the effect of n iterations is same as one of n+1 iterations.
It is still the same thing pronounced several times: A and A = A.

Making a declaration statement should consequently allow this:

   X : Integer := 1;
   Foo (X);
   X : Float := 2.0;
   Boo (X);

If it is just a statement, why can't I re-execute it?

>>> 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.

But "handle" would be still confusing:

handle
   X : constant ...;
   Y : constant ...;
   Do_Something (X, Y);
exception
   when Foo_Error =>
      Do_Something_Interesting (X, Y); -- Illegal
end;

There is no obvious way to mix declarations and statements being able to
handle exceptions from both at the same level.

Maybe I could explain why I don't enjoy the "performance" in another way.
In my eyes declarations have a "declared" persistent effect. It is a name
bound to some new object and the object itself. Statements don't have such
effects.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2008-06-16 20:30 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
2008-06-16  8:31                       ` Dmitry A. Kazakov
2008-06-16 19:17                         ` Robert A Duff
2008-06-16 20:30                           ` Dmitry A. Kazakov [this message]
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