comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <rm.dash-bauhaus@futureapps.de>
Subject: Re: About String
Date: Mon, 09 Jun 2008 13:43:21 +0200
Date: 2008-06-09T13:43:21+02:00	[thread overview]
Message-ID: <484d1759$0$6620$9b4e6d93@newsspool2.arcor-online.net> (raw)
In-Reply-To: <f9xabk2p1obj$.1j3yto2qfpxpc.dlg@40tude.net>

Dmitry A. Kazakov schrieb:

>> Given linear order of elaboration in declarative parts,
>> and thus the possibility of sequencing initialization
>> of local variables:
>>
>>    procedure P is
>>       declare
>>          X1: constant T;  -- like Java final
>>       begin
>>          X1 := New_T(...);  -- may raise CE
>>       exception
>>          when Constraint_Error =>
>>              X1 := Fallback_T;  -- better than Java final
>>       end;
>>       X2: D := New_D(X1, ...);  -- safely refer to X1
>>    begin
>>       ...
>>    end P;
> 
> Huh, if you want closures, just say so. There is no need to break proven
> language concepts in order to have desired effect:

I should have said that the scope of X1 extends beyond
the declare block (which I had stupidly chosen as key words).

> procedure P is
>     X1: constant T := -- Here anonymous function literal begins
>        function return T is
>        begin
>             return New_T (...);  -- may raise CE
>        exception
>           when Constraint_Error =>
>               return Fallback_T;  -- better than Java final
>        end;
>    X2: D := New_D (X1, ...);  -- safely refer to X1
> begin
>    ...
> end P;


Why closures? I was about to mention nesting, which
solves this issue in Ada 95 and Ada:

procedure P is
    function Safe_T return T is
    begin
       return New_T (...);  -- may raise CE
    exception
       when Constraint_Error =>
          return Fallback_T;  -- better than Java final
    end;
    X1: constant T := Safe_T;

    X2: D := New_D (X1, ...);  -- safely refer to X1
begin
    ...
end P;

In a sense, Safe_T works just like constructors that don't raise.


> Note, no magic stuff, no exception handlers in declarations, just a simple
> thing, which Ada should have had from the day one: functional types and
> literals of.

With the function's full environment?



  parent reply	other threads:[~2008-06-09 11:43 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 [this message]
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
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