comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Proposal: Constructors, Assignment [LONG]
Date: Tue, 31 Dec 2002 18:28:35 -0600
Date: 2002-12-31T18:28:35-06:00	[thread overview]
Message-ID: <v14dhge1o45s61@corp.supernews.com> (raw)
In-Reply-To: aus4g6$9v52j$1@ID-77047.news.dfncis.de

Dmitry A. Kazakov wrote in message ...
>I do not understand how could this work. According to Nick Roberts the
>result of Make_Session is copied as-is. But the object returned by
>Make_Session has to be pointed from OUTSIDE:


Right. That's the "new feature" in the proposal. And it's relatively
cheap, since compilers typically handle composite functions by creating
memory at the point of the call and passing it in to the function with a
hidden parameter. Might as well make that explicit.

>function Make_Session (Count: Integer) return Internet_Session is
>   Result : Internet_Session (Count);
>begin
>--
>-- Place the new object in front of the list
>--
>   Result.Previous := Global_List_Header'Unchecked_Access;
>   Result.Next := Global_List_Header.Next;
>   Global_List_Header.Next := Result'Unchecked_Access;
>   Global_List_Header.Next.Previous := Result'Unchecked_Access;
>   return Result;
>end Make_Session;
>
>How to fix this?


The syntax of the proposal wasn't determined, but the basic idea was
something like:

function Make_Session (Count: Integer) return Internet_Session is
   Result : return Internet_Session (Count);
begin
--
-- Place the new object in front of the list
--
   Result.Previous := Global_List_Header'Unchecked_Access;
   Result.Next := Global_List_Header.Next;
   Global_List_Header.Next := Result'Unchecked_Access;
   Global_List_Header.Next.Previous := Result'Unchecked_Access;
   return Result;
end Make_Session;

With this declaration, "Result" is passed in implicitly from the caller
for a limited type, and it must be returned. Returning some other object
or none at all is an error. There can be only one such object (only one
object can be passed in).

>...
>Absolutely. The rest is easy, it is just to explain why "not-copying"
have
>to be spelled as copying:
>
>X : Obj := Func (<args>);
>
>Isn't it misleading? We already have functions that are not functions.
Now
>we will have even more non-functions, and also non-results of
>non-assignments. I wonder why all this is not counted as a "new
feature"?


Because we already have it in Ada 95 for aggregates (see AI-83 and the
corrigendum). So we're just extending what's already available.

>...
>Class-wide objects cannot be constructed.

I don't get this at all. What's wrong with:

    A : T'Class := Construct_Class (...);

where the definition of Construct_Class uses some mechanism to dispatch
properly.

(Note that you virtually always end up with a case statement in
Construct_Class, because you somehow have to get from a set of arbitrary
parameter values to some tag. There is no automatic way to do that in
any programming language that I know of. If you're really clever, you
can use T'Class'Input to do this, but its a real hack.)

               Randy.






  reply	other threads:[~2003-01-01  0:28 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-12-24 11:16 Proposal: Constructors, Assignment [LONG] Dmitry A. Kazakov
2002-12-26 22:11 ` Nick Roberts
2002-12-27 17:43   ` Dmitry A. Kazakov
2002-12-27 20:17     ` Randy Brukardt
2002-12-29 13:43       ` Dmitry A. Kazakov
2002-12-29 18:45         ` Nick Roberts
2002-12-30 12:23           ` Dmitry A. Kazakov
2002-12-30 15:14             ` Robert A Duff
2002-12-31 13:02               ` Dmitry A. Kazakov
2003-01-01  0:28                 ` Randy Brukardt [this message]
2003-01-01 14:13                   ` Dmitry A. Kazakov
2003-01-02 19:44                     ` Randy Brukardt
2003-01-03 13:21                       ` Dmitry A. Kazakov
2003-01-03 19:29                         ` Randy Brukardt
2003-01-03 20:50                       ` Robert A Duff
2003-01-04 12:53                         ` Dmitry A. Kazakov
2003-01-01  0:54         ` Randy Brukardt
2003-01-01 14:13           ` Dmitry A. Kazakov
2003-01-02 19:36             ` Randy Brukardt
2003-01-03 13:20               ` Dmitry A. Kazakov
replies disabled

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