From: stefan-lucks@see-the.signature
Subject: Re: Ada2012 : Expression functions and extended return statements
Date: Sat, 7 Jan 2012 15:54:44 +0100
Date: 2012-01-07T15:54:44+01:00 [thread overview]
Message-ID: <Pine.LNX.4.64.1201071552090.1883@medsec1.medien.uni-weimar.de> (raw)
In-Reply-To: <bdd18755-48cd-4166-bba2-3823e58ad033@e2g2000vbb.googlegroups.com>
On Fri, 6 Jan 2012, Martin wrote:
> On Jan 6, 9:45�am, stefan-lu...@see-the.signature wrote:
> > On Fri, 6 Jan 2012, Martin wrote:
> > > Also, on the topic of extended return statements...
> >
> > > What's the rational for having to explicitly repeat the return type?
> > > Seems rather redundant to my eyes. I wouldn't have minded:
> >
> > I guess, this is because the object actually returned may not necessarily
> > be of exactly the same type of subtype as the declared return type -- like
> > the ordinary return statement. See the following examples:
> >
> > � �function Characters(I: Integer; Filler: Character := '_') return String is
> > � �begin
> > � � � return Result: String(1..I) := (others => Filler) do
> > � � � � return;
> ^^^^^^^
>
> I think you mean
> null;
> or
> return Result: String(1..I) := (others => Filler);
The following compiles fine (with gnat 2011), and the output is xxxyyx, as
to be expected:
<lang Ada>
with Ada.Text_IO;
procedure Y is
function Characters(I: Integer; Filler: Character := '_') return String is
begin
return Result: String(1..I) := (others => Filler) do
return;
end return;
end Characters;
begin
Ada.Text_IO.Put(Characters(3, 'x'));
Ada.Text_IO.Put(Characters(2, 'y'));
Ada.Text_IO.Put(Characters(1, 'x'));
Ada.Text_IO.Put(Characters(0, 'y'));
end Y;
</lang>
>
> > � � � end return;
> > � �end Characters;
> >
> > � �type T is tagged record I: Integer; end record;
> > � �type S is new T with record J: Natural; end record;
> >
> > � �function Fun(N, M: Natural) return T'Class is
> > � �begin
> > � � � return Result: S do
> > � � � � Result.I := M;
> > � � � � Result.J := N;
> > � � � end return;
> > � �end Fun;
> >
> > --
> > ---- Stefan.Lucks (at) uni-weimar.de, University of Weimar, Germany �----
> > � � <http://www.uni-weimar.de/cms/medien/mediensicherheit/home.html>
> > ------ �I �love �the �taste �of �Cryptanalysis �in �the �morning! �------
>
>
> Ah ok, yes, that makes sense...thanks. Never had need of
> this...yet! :-)
>
> 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.
>
> -- Martin
>
--
---- Stefan.Lucks (at) uni-weimar.de, University of Weimar, Germany ----
<http://www.uni-weimar.de/cms/medien/mediensicherheit/home.html>
------ I love the taste of Cryptanalysis in the morning! ------
next prev parent reply other threads:[~2012-01-07 14:57 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
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 [this message]
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