comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: another way to shoot yourself in the foot?
Date: Tue, 24 Jun 2008 16:31:31 -0400
Date: 2008-06-24T16:31:31-04:00	[thread overview]
Message-ID: <wcc7icer2vw.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: mJb8k.169946$TT4.122323@attbi_s22

"Jeffrey R. Carter" <spam.jrcarter.not@spam.acm.org> writes:

> Robert A Duff wrote:
>> Well, I don't think so, but anyway, this is the only way
>> return of limited types can make sense.  The Ada 83 way
>> (return is by copy, even for limited) is just wrong.
>> And the Ada 95 way (return by reference) is confusing
>> and nearly useless.
>
> I don't know about "nearly useless". The only thing you could do with a
> limited function result in Ada 95 (and Ada 83) was pass it to a
> subprogram or entry.

Not quite the "only" -- you could rename it.

> ...There are times when that is useful.

But in Ada 95, if you say:

    P(F(...));

where F returns limited, you are not passing a limited object,
but an implicit reference to some object that already existed before the
call to F.  You can do that more clearly by having F return
an access type.  I really think return-by-ref was a mistake.
Too bad we didn't think of it in 1992.  For that matter, too
bad JDI didn't think of it in 1980. ;-)

> The new way seems to be biased towards build in place for object
> initialization.

Well, there are only two ways a function call can be used: to initialize
a new object, or to update an existing object (i.e. on the right-hand
side of an assignment statement).  But don't forget there are a dozen or
so different ways of creating new objects (components, parameters,
parent parts of aggregates, etc).  All of these are allowed for
build-in-place function calls.  The only thing that's not allowed is the
assignment statement.

You can still say:

    P(F(...));

where F returns a limited type.  Yes, there's a new object being created
(the formal parameter of P), and F is being used to initialize that
object (in place!).  In Ada 2005, functions always return newly-created
objects, which I think is appropriate.

A couple more examples:

    X : Array_Of_Lim := (1..10 => F(...));

    if F(...).Flag then ...

The last one is pretty silly -- it creates a new limited object,
grabs a boolean flag out of it, and then throws the whole thing
away.

- Bob



  reply	other threads:[~2008-06-24 20:31 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-20  9:03 another way to shoot yourself in the foot? fedya_fedyakoff
2008-06-20  9:34 ` Dmitry A. Kazakov
2008-06-20  9:48   ` fedya_fedyakoff
2008-06-20 10:01     ` Ludovic Brenta
2008-06-20 10:05 ` christoph.grein
2008-06-20 10:26   ` Dmitry A. Kazakov
2008-06-20 16:12     ` Adam Beneschan
2008-06-20 15:48   ` Adam Beneschan
2008-06-20 19:27   ` Robert A Duff
2008-06-20 23:37     ` Jeffrey R. Carter
2008-06-21  8:56       ` Dmitry A. Kazakov
2008-06-22 20:44         ` Robert A Duff
2008-06-23  7:49           ` Dmitry A. Kazakov
2008-06-24  4:02             ` george.priv
2008-06-24  7:30               ` Dmitry A. Kazakov
2008-06-24 17:16                 ` Robert A Duff
2008-06-24 19:15                   ` Jeffrey R. Carter
2008-06-24 20:31                     ` Robert A Duff [this message]
2008-06-24 20:50                       ` Ludovic Brenta
2008-06-24 23:02                         ` Robert A Duff
2008-06-24 23:42                         ` Georg Bauhaus
2008-06-24 21:24                       ` Jeffrey R. Carter
2008-06-24 23:24                         ` Robert A Duff
2008-06-25 15:07                       ` Adam Beneschan
2008-06-24 14:59             ` Adam Beneschan
2008-06-24 16:41               ` Dmitry A. Kazakov
2008-06-24 17:20                 ` Robert A Duff
2008-06-24 17:52                   ` Dmitry A. Kazakov
2008-06-24 23:35                     ` Georg Bauhaus
2008-06-25  8:09                       ` Dmitry A. Kazakov
2008-06-25 10:32                         ` Georg Bauhaus
2008-06-25 12:06                           ` Dmitry A. Kazakov
2008-06-22 20:37       ` Robert A Duff
2008-06-22 21:25         ` Jeffrey R. Carter
2008-07-04 20:52           ` Colin Paul Gloster
2008-07-04 22:15             ` (see below)
2008-07-05 16:06               ` Colin Paul Gloster
2008-07-05 13:38             ` Gary Scott
2008-07-05 16:42               ` Colin Paul Gloster
2008-07-05 19:00                 ` Gary Scott
2008-07-09 19:39                   ` Colin Paul Gloster
2008-07-09 20:35                     ` Richard Maine
2008-07-09 22:49                       ` Terence
2008-07-10  1:07                         ` Gary Scott
2008-07-10 14:10                       ` Colin Paul Gloster
2008-07-10 14:57                         ` fj
2008-07-10 16:47                           ` Richard Maine
2008-07-10 17:03                         ` Dick Hendrickson
2008-07-10 17:26                           ` Craig Powers
2008-07-10 19:55                             ` James Giles
2008-07-10 20:45                               ` Dick Hendrickson
2008-07-10 21:22                                 ` Richard Maine
2008-07-10 21:29                                   ` Craig Powers
2008-07-10 20:45                               ` Craig Powers
2008-07-10 19:51                           ` James Giles
2008-07-11 15:02                             ` Colin Paul Gloster
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox