Talk About Network

Google





Programming > Ada > Re: About Strin...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 24 of 38 Topic 5743 of 6006
Post > Topic >>

Re: About String

by =?ISO-8859-1?Q?S=E9bastien_Morand?= <seb.morand@[EMAIL PROTECTED] > Jun 9, 2008 at 10:42 AM

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Dmitry A. Kazakov a écrit :
> On Mon, 09 Jun 2008 11:43:36 +0200, Georg Bauhaus wrote:
> 
>> Dmitry A. Kazakov schrieb:
> 
>>> On Sun, 08 Jun 2008 17:19:11 -0400, Robert A Duff wrote:
>>>
>>>> Maciej Sobczak <see.my.homepage@[EMAIL PROTECTED]
> writes:
>>>>
>>>>> After all, with the possibility to initialize the new variable with
>>>>> arbitrarily complex expression (including function call), this is
>>>>> already the case and the whole declare-begin-end block is just
>>>>> reflecting some artificial separation.
> 
>>>> 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.
>  
>> Still, a somewhat *new* kind kind of handling exceptions in single
>> declarations looks interesting?
> 
>> 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:
> 
> 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;
> 
> 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.

You can do that but not in an anonymous way, so what's the point? I
think it not a good practive to use anonymous function or procedure, it
makes hard to read code (and it's one of the feature of ada: easy to read)

I prefer this kind of writing:
procedure P is

   function Init_T return T;

   function Init_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 := Init_T; -- Here anonymous function literal begins
   X2: D := New_D (X1, ...);  -- safely refer to X1

begin
   ...
end P;
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Cygwin)

iD8DBQFITQkK+zV9xm4PlDQRAnhxAJ9FKGI7aVenIlDrrnsl3LHJE42FJQCfV9lc
Vvl0CozDP7p/Ah44Ivnz4G8=
=bdGO
-----END PGP SIGNATURE-----
 




 38 Posts in Topic:
About String
=?ISO-8859-1?Q?S=E9bastie  2008-06-06 17:29:43 
Re: About String
Simon Wright <simon.j.  2008-06-07 17:18:12 
Re: About String
Pascal Obry <pascal@[E  2008-06-07 19:01:07 
Re: About String
Chris Moore <zmower@[E  2008-06-07 23:13:16 
Re: About String
Niklas Holsti <niklas.  2008-06-08 09:47:30 
Re: About String
"Dmitry A. Kazakov&q  2008-06-08 09:35:31 
Re: About String
Sebastien Morand <seb.  2008-06-08 10:29:53 
Re: About String
"Dmitry A. Kazakov&q  2008-06-08 12:53:16 
Re: About String
Niklas Holsti <niklas.  2008-06-08 14:14:04 
Re: About String
"Dmitry A. Kazakov&q  2008-06-08 15:16:54 
Re: About String
Niklas Holsti <niklas.  2008-06-08 20:17:33 
Re: About String
"Dmitry A. Kazakov&q  2008-06-09 09:26:26 
Re: About String
Chris Moore <zmower@[E  2008-06-08 19:26:21 
Re: About String
Robert A Duff <bobduff  2008-06-08 14:32:36 
Re: About String
Simon Wright <simon.j.  2008-06-08 12:13:50 
Re: About String
Sebastien Morand <seb.  2008-06-08 19:03:17 
Re: About String
Martin <martin.dowie@[  2008-06-08 04:48:56 
Conditional declarations (was: About String)
"Dmitry A. Kazakov&q  2008-06-08 15:17:03 
Re: About String
Maciej Sobczak <see.my  2008-06-08 13:51:07 
Re: About String
Robert A Duff <bobduff  2008-06-08 17:19:11 
Re: About String
"Dmitry A. Kazakov&q  2008-06-09 09:14:30 
Re: About String
Georg Bauhaus <rm.dash  2008-06-09 11:43:36 
Re: About String
"Dmitry A. Kazakov&q  2008-06-09 12:25:02 
Re: About String
=?ISO-8859-1?Q?S=E9bastie  2008-06-09 10:42:18 
Re: About String
Georg Bauhaus <rm.dash  2008-06-09 13:43:21 
Re: About String
"Dmitry A. Kazakov&q  2008-06-09 14:03:37 
Re: About String
Robert A Duff <bobduff  2008-06-15 15:38:08 
Re: About String
"Dmitry A. Kazakov&q  2008-06-15 22:52:45 
Re: About String
Robert A Duff <bobduff  2008-06-15 18:06:00 
Re: About String
"Dmitry A. Kazakov&q  2008-06-16 10:31:03 
Re: About String
Robert A Duff <bobduff  2008-06-16 15:17:15 
Re: About String
"Dmitry A. Kazakov&q  2008-06-16 22:30:12 
Re: About String
Georg Bauhaus <rm.tsoh  2008-06-17 00:02:51 
Re: About String
Robert A Duff <bobduff  2008-06-16 19:04:54 
Re: About String
Georg Bauhaus <rm.dash  2008-06-09 13:00:44 
Re: About String
Robert A Duff <bobduff  2008-06-15 15:48:49 
Re: About String
Britt Snodgrass <britt  2008-06-09 07:27:05 
Re: About String
Robert A Duff <bobduff  2008-06-15 15:50:13 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
localhost-V2008-12-19 Wed Jan 7 14:54:44 PST 2009.