comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Proposal: Constructors, Assignment [LONG]
Date: Fri, 27 Dec 2002 14:17:03 -0600
Date: 2002-12-27T14:17:03-06:00	[thread overview]
Message-ID: <v0pd8uc2ie1eb8@corp.supernews.com> (raw)
In-Reply-To: aui3fc$79ev8$1@ID-77047.news.dfncis.de

I think that for this proposal to get serious consideration, you'll have
to give rules to plug the many holes in it:

-- You'd need to carefully explain why solutions based on functions (as
Nick Roberts described) are not sufficient;

-- You'll need to explain how this works for controlled types (an
incompatibility there is simply not going to be tolerated);

-- You'll need to determine the rules for these in generics. Your
current description would be a giant contract model violation, and that
needs to be fixed. In particular, for a generic formal private type:
   generic
      type Priv is private;
what 'Get_Constructor and 'Initialize routines can be called? The fact
that these are different in profile is simply not going to fly here (and
I doubt that banning the use of constructors in generic bodies is going
to be an acceptable solution).

-- You'll need to explain how this works in the face of disappearing
components on an assignment. That has been the problem that has killed
all previous proposals like this one. See
    http://www.adaic.org/standards/95aarm/html/AA-7-6.html, paragraphs
17.a-17.h for a discussion.


I'd prefer making the function solution work. There is a proposal to
make it possible to initialize limited objects with a function call,
which would eliminate that objection.

Your other objection:

>The idea that a constructor is just a function is IMO badly wrong.
Limited
>types is just one example why. Another example is class-wide types. How
to
>construct a class-wide object from scratch? To write a class-wide
function?
>But then it will never ever dispatch. A dispatching one? But the type
is
>unknown and there is no object. This is why Ada's stream attributes are
>made hard-wired. This is also why assignment is a problem.


The bug, IMHO, is that you can't write T'Class'Input in Ada. Its
terrible that magic is needed there, because its clear that there are
other cases where that sort of code would be useful.

We investigated some solutions to that problem in the past. The primary
problem is how to get the object created for a particular value of
Ada.Tags.Tag. A direct approach doesn't work, because you don't know how
to initialize the discriminants (they can be different for extensions
than for the base type). However, an approach based on using the tag
value to control dispatching of a function (rather than a result object)
does work. And it is very simple to implement (as compilers are
essentially dispatching on a value of Ada.Tags.Tag anyway). However,
most people thought that inventing syntax to solve this problem was too
heavy, and there really isn't any alternative. So nothing much has been
done on this problem.

The basic idea is to somehow figure a value of Ada.Tags.Tag, then use it
to control dispatching on a function that returns the correct kind of
object. This requires a special call:

      Obj : T'Class := Func (<args>) use Tag_Value;

With these two capabilities, I believe that functions provide
appropriate constructors, and you don't necessarily need to use a
'handle' implementation. (I suspect that in practice, you often will
want to use a handle implementation anyway, but I certainly agree that
you shouldn't be forced into it.) Leveraging existing language features
is far preferable to inventing a whole new mechanism.

           Randy Brukardt.







  reply	other threads:[~2002-12-27 20:17 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 [this message]
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
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