From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,ee887b7593f7961b X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!feeder.news-service.com!newsfeed.freenet.de!bolzen.all.de!newsfeed.ision.net!newsfeed2.easynews.net!ision!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Programmer controlled object creation Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <1pmkcuemqczer.j2i34pvc2lne$.dlg@40tude.net> <81912719-8c66-439d-a40e-529b22acd8a6@u29g2000pro.googlegroups.com> <14t6hwu8udm8j$.1x339y69m2ew1.dlg@40tude.net> <14ay3vz2ngj9s.1bmilwgckl3lc$.dlg@40tude.net> <491eb919$0$31346$9b4e6d93@newsspool4.arcor-online.net> Date: Sat, 15 Nov 2008 13:44:01 +0100 Message-ID: NNTP-Posting-Date: 15 Nov 2008 13:44:03 CET NNTP-Posting-Host: 87b62bf8.newsspool4.arcor-online.net X-Trace: DXC=4][Hc?@KkWfPKPPVf;4hUj4IUKKaDNcfSJ;bb[eIRnRBaCdQe9k4e X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:8415 Date: 2008-11-15T13:44:03+01:00 List-Id: 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" 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