From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Ada2012 : Expression functions and extended return statements
Date: Fri, 6 Jan 2012 14:13:01 +0100
Date: 2012-01-06T14:13:01+01:00 [thread overview]
Message-ID: <ycaiu0alika0.1antlb0rkzl1g.dlg@40tude.net> (raw)
In-Reply-To: 94808f24-938b-476e-8912-f98b52982d53@j10g2000vbe.googlegroups.com
On Fri, 6 Jan 2012 03:37:27 -0800 (PST), Martin wrote:
> On Jan 6, 11:23�am, "Peter C. Chapin" <PCha...@vtc.vsc.edu> wrote:
>> On 2012-01-06 05:02, Martin wrote:
>>
>>> I still think it would be nice to have a short-hand e.g. 'return
>>> Result :<> �do'. If anything it would then draw the eye to the more
>>> interesting case when the 2 are different.
>>
>> You need to repeat the type for ordinary returns as well.
>>
>> function F return Integer is
>> � �Result : Integer; �-- Duplication of return type here.
>> begin
>> � �Result := 1;
>> � �return Result;
>> end F;
>>
>> To be consistent it seems like you'd need to be able to use '<>'
>> throughout the body of the function.
>>
>> function F return Integer is
>> � �Result : <>; �-- Shorthand for function's return type.
>> begin
>> � �Result := 1;
>> � �return Result;
>> end F;
>>
>> Considering Ada's tendency to require one to repeat information in
>> earlier declarations, this seems a bit unAda-like to me. Also this would
>> allow '<>' to show up in a lot of strange looking places such as type
>> conversions and type qualifications.
>>
> The difference is that the declaration of 'Return' in the extended
> return is that the compiler 'knows' that this is the declaration of
> something that's going to be returned - it can't know that in the
> ordinary return case.
This is not a declaration, because the result is not an object.
Note that your argument applies to other parameters of a subprogram:
procedure Foo (X : Integer); -- Declares X
procedure Foo (X : Integer) is -- Reiterates what is already known
...
end Foo;
> It would certainly be a departure from current Ada - adding a little
> bit of "Type Inferencing" to the language. But I'm not adverse to
> that...so long as the inferencing is safe. I like SML/NJ :-)
Maybe. There are lots of cases where repetition is boring and error prone.
E.g.:
if X in T'Class then
declare
XX : T'Class renames T'Class (X);
or
if X /= null then
declare
XX : T renames X.all;
or
X : Subarray renames Array_Thing; -- Legal, but broken
As for return, the second best (the first one is to ditch return statement
altogether) would be:
X : return -- Loop label syntax
...
end X;
BTW, Ada could have the result explicitly named like other parameters are.
E.g.
function F return X : Integer := 1 is
begin
if Something then
X := 2;
end if;
end F; -- No explicit return needed, obviously
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
next prev parent reply other threads:[~2012-01-06 13:14 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-06 8:45 Ada2012 : Expression functions and extended return statements Martin
2012-01-06 9:45 ` stefan-lucks
2012-01-06 10:02 ` Martin
2012-01-06 11:23 ` Peter C. Chapin
2012-01-06 11:37 ` Martin
2012-01-06 13:13 ` Dmitry A. Kazakov [this message]
2012-01-06 14:45 ` Martin Dowie
2012-01-06 15:07 ` Martin
2012-01-06 16:40 ` Robert A Duff
2012-01-06 17:04 ` Martin Dowie
2012-01-19 7:47 ` David Thompson
2012-01-06 17:20 ` Dmitry A. Kazakov
2012-01-07 1:47 ` Randy Brukardt
2012-01-07 9:21 ` Dmitry A. Kazakov
2012-01-06 16:45 ` Adam Beneschan
2012-01-06 16:36 ` Adam Beneschan
2012-01-07 14:54 ` stefan-lucks
2012-01-07 15:11 ` Dmitry A. Kazakov
2012-01-08 9:41 ` stefan-lucks
2012-01-09 6:16 ` Randy Brukardt
2012-01-06 15:11 ` J-P. Rosen
2012-01-06 15:26 ` Martin
2012-01-07 1:50 ` Randy Brukardt
2012-01-07 10:12 ` Martin
2012-01-07 12:22 ` Simon Wright
2012-01-07 17:10 ` Martin
2012-01-09 6:21 ` Randy Brukardt
2012-01-09 7:57 ` Martin Dowie
2012-01-31 23:34 ` Yannick Duchêne (Hibou57)
2012-01-06 16:33 ` Adam Beneschan
2012-01-06 16:38 ` Adam Beneschan
2012-01-06 22:12 ` Robert A Duff
2012-01-31 23:20 ` Yannick Duchêne (Hibou57)
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox