comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Overring function and its returned type
Date: Mon, 19 Nov 2012 17:42:47 -0600
Date: 2012-11-19T17:42:47-06:00	[thread overview]
Message-ID: <k8eg5t$b86$1@munin.nbi.dk> (raw)
In-Reply-To: op.wn0ieqnqule2fv@cardamome

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2473 bytes --]

"Yannick Duch�ne (Hibou57)" <yannick_duchene@yahoo.fr> wrote in message 
news:op.wn0ieqnqule2fv@cardamome...
>Le Sun, 18 Nov 2012 15:53:28 +0100, AdaMagica 
><christ-usch.grein@t-online.de> a �crit:
>
...
>> How can this be? The actual of an out-parameter exists already, whereas 
>> the return object is newly created.
>
>He meant it, semantically. You can return a value into an already existing 
>object, and in practice, except with purely functional languages, that's 
>always how it goes (even if the target may be adjusted in some way for 
>many reasons).

That's definitely *not* the case in Ada - "always" is way too strong here. 
There are a number of ways for the result of a function to be a new object 
that is never put into an existing object. Two that come to mind are:

      A := F(I).Comp; -- where Comp is a record component of an elementary 
type.

The record object returned by F(I) is never put into any existing object in 
this case, and even the component is copied. I've occassionally done this in 
my programs.

    P (F(I)); -- P is a procedure with an "in" parameter of the type of 
F(I).

Here, the record object returned by F(I) is passed to P; again this is a new 
object that is never put into an existing object. I've done this quite a few 
times in my programs.

Cases like this complicate the definition of function returns in Ada, and 
these are quite different than the situation with "out" parameters (which 
cannot create a new object). (They also complicate the finalization rules, 
as you might guess.)

I know that Bob has always wanted "out" parameters and function results to 
work as similarly as possible, but it should be clear that there are 
differences between them that are fundemental. I don't think that a language 
could work without something like function results ("out" parameters aren't 
quite so fundemental). You could get them closer in Ada if you could somehow 
allow more objects to have mutable discriminants and especially mutable 
array bounds, but I think that would make most objects more expensive than 
Ada's currently are (much more dynamic allocation would be required). And 
you still need very short-lived objects (as in the examples above).

                                             Randy.




-- 
"Syntactic sugar causes cancer of the semi-colons." [1]
"Structured Programming supports the law of the excluded muddle." [1]
[1]: Epigrams on Programming - Alan J. - P. Yale University 





  parent reply	other threads:[~2012-11-19 23:42 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-09  7:13 Overring function and its returned type Yannick Duchêne (Hibou57)
2012-11-09  7:22 ` Yannick Duchêne (Hibou57)
2012-11-09  8:24 ` Dmitry A. Kazakov
2012-11-09  9:14   ` Yannick Duchêne (Hibou57)
2012-11-09 13:11     ` Dmitry A. Kazakov
2012-11-09 21:36       ` Yannick Duchêne (Hibou57)
2012-11-09 19:24   ` Adam Beneschan
2012-11-09 19:34 ` Adam Beneschan
2012-11-09 22:00   ` J-P. Rosen
2012-11-09 22:30     ` Yannick Duchêne (Hibou57)
2012-11-09 19:57 ` sbelmont700
2012-11-09 21:10   ` Yannick Duchêne (Hibou57)
2012-11-09 21:56     ` sbelmont700
2012-11-10  0:28     ` Yannick Duchêne (Hibou57)
2012-11-10  2:35       ` Yannick Duchêne (Hibou57)
2012-11-15 15:13   ` Peter C. Chapin
2012-11-16 10:40     ` Maciej Sobczak
2012-11-16 12:39       ` Peter C. Chapin
2012-11-16 15:27         ` Maciej Sobczak
2012-11-16 17:29           ` Peter C. Chapin
2012-11-17  4:16           ` Yannick Duchêne (Hibou57)
2012-11-17 19:11             ` Robert A Duff
2012-11-18 14:53               ` AdaMagica
2012-11-19  8:41                 ` Yannick Duchêne (Hibou57)
2012-11-19 13:04                   ` AdaMagica
2012-11-19 15:19                     ` Dmitry A. Kazakov
2012-11-19 23:42                   ` Randy Brukardt [this message]
2012-11-10  7:55 ` Randy Brukardt
2012-11-11  1:02   ` 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