From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Programmer controlled object creation
Date: Sat, 15 Nov 2008 13:44:01 +0100
Date: 2008-11-15T13:44:03+01:00 [thread overview]
Message-ID: <swiaobuqy47j.18i6enu1g1582$.dlg@40tude.net> (raw)
In-Reply-To: 491eb919$0$31346$9b4e6d93@newsspool4.arcor-online.net
On Sat, 15 Nov 2008 12:57:12 +0100, Georg Bauhaus wrote:
> Dmitry A. Kazakov wrote:
>> On Fri, 14 Nov 2008 18:11:34 -0500, Robert A Duff wrote:
>>
>>> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
>>>
>>>> On Tue, 11 Nov 2008 17:09:54 -0500, Robert A Duff wrote:
>>>>> Initialization: Use function calls. They work for all types.
>>>>> I think we've discussed this idea before, but I don't remember
>>>>> any fundamental problems.
>>>> The fundamental problem is that a constructor cannot be decomposed into
>>>> functions. In the function body you have to construct the object before you
>>>> return it. Who does it and what?
>>> In Ada 2005, a constructor function creates the object via another
>>> function call, or via an aggregate, or via an uninitialized
>>> variable (to which it assigns components).
>>
>> Here we are. At the end of this chain there is always some magical
>> construct which is not a function. It is the construct which yields the
>> object of the type. The object is *already* constructed at this point, per
>> magic, not per function which is not yet even returned.
>
> So what would programmer controlled object creation
> look like? I'm assuming you want the compiler to check
> that usual Ada semantics is still intact. That is, all decisions about
> size, alignment, placement, etc.
>
> There be partial construction, IIUC? That is, some components
> may be constructed late: Another function gets the partially
> constructed object? That is,
>
> function Make_Pizza (Hunger: Size) return Pizza;
> pragma Convention (Constructor, Make_Pizza);
>
> procedure Add_Topping (Object: in out Pizza; ...);
> -- creates a Topping component and fills it
> pragma Convention (Constructor, Add_Topping);
>
> type Pizza is tagged
> record
> Dough: Positive range 200 .. 1_000;
> Topping: ...;
> end record;
>
> function Make_Pizza (Hunger: Size) return Pizza is
> begin
> return Result: Pizza do
> -- we would NOT have an Object yet
>
> Pizza'Constructor(Dough => Grams (Hunger));
> -- we may NOT have a Topping component yet
>
> Add_Topping(Result);
> -- pass partial object (or info about it?)
>
> -- now we have a Topping component
> end return;
> end Make_Pizza;
Nothing like that. A proposal was posted long ago:
http://groups.google.de/group/comp.lang.ada/browse_frm/thread/72c34c66b38e0e05?ie=UTF-8&oe=utf-8
The proposed sugar for constraints evaluation and construction hooks was:
function Pizza'Get_Constraints (...) return Pizza'Constraints;
procedure Pizza'Initialize (X : in out Pizza; ...);
The proposal contained examples of how the components become their
constraints from the parameters of a factory function. Of course there was
no such thing like partially constructed components.
BTW, it is Ada 2005 new feature that allows something like partial
construction:
function Make return T is
begin
return R : T do
...
raise I_Do_Not_Like_It;
end return;
exception
when I_Do_Not_Like_It =>
return R : T do
...
end return;
end Make;
Here the result is constructed twice.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
next prev parent reply other threads:[~2008-11-15 12:44 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-07 14:10 Ada OS based on Minix3 Cedric.Lannock
2008-11-07 16:20 ` xavier grave
2008-11-08 3:46 ` anon
2008-11-10 8:12 ` Ivan Levashew
2008-11-10 8:58 ` Dmitry A. Kazakov
2008-11-10 9:26 ` Ivan Levashew
2008-11-10 10:11 ` Georg Bauhaus
2008-11-10 10:24 ` Jacob Sparre Andersen
2008-11-10 10:51 ` Dmitry A. Kazakov
2008-11-10 11:07 ` Ludovic Brenta
2008-11-10 11:42 ` Ivan Levashew
2008-11-10 12:04 ` Ludovic Brenta
2008-11-11 22:16 ` Robert A Duff
2008-11-12 6:28 ` Ivan Levashew
2008-11-10 10:50 ` Ivan Levashew
2008-11-10 11:01 ` Dmitry A. Kazakov
2008-11-10 15:31 ` Robert A Duff
2008-11-10 15:56 ` Dmitry A. Kazakov
2008-11-11 22:09 ` Robert A Duff
2008-11-12 9:47 ` Dmitry A. Kazakov
2008-11-13 0:58 ` Randy Brukardt
2008-11-13 17:28 ` Dmitry A. Kazakov
2008-11-13 23:25 ` Randy Brukardt
2008-11-14 9:30 ` Dmitry A. Kazakov
2008-11-14 23:11 ` Robert A Duff
2008-11-15 10:04 ` Dmitry A. Kazakov
2008-11-15 11:57 ` Programmer controlled object creation (was: Re: Ada OS based on Minix3) Georg Bauhaus
2008-11-15 12:44 ` Dmitry A. Kazakov [this message]
2008-11-10 10:18 ` Ada OS based on Minix3 Georg Bauhaus
2008-11-11 1:00 ` Freejack
2008-11-11 8:32 ` Martin Krischik
2008-11-11 11:09 ` Peter C. Chapin
2008-11-11 11:59 ` Georg Bauhaus
2008-11-11 14:35 ` Ludovic Brenta
2008-11-11 16:49 ` Georg Bauhaus
2008-11-13 7:10 ` Martin Krischik
2008-11-13 7:01 ` Martin Krischik
2008-11-13 6:48 ` Martin Krischik
2008-11-13 8:09 ` Thomas Locke
2008-11-13 10:16 ` Alex R. Mosteo
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox