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: g2news1.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!newsfeed.straub-nv.de!noris.net!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Sat, 15 Nov 2008 12:57:12 +0100 From: Georg Bauhaus Reply-To: rm.tsoh-bauhaus@maps.futureapps.de User-Agent: Thunderbird 2.0.0.17 (X11/20080925) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Programmer controlled object creation (was: Re: Ada OS based on Minix3) References: <1pmkcuemqczer.j2i34pvc2lne$.dlg@40tude.net> <81912719-8c66-439d-a40e-529b22acd8a6@u29g2000pro.googlegroups.com> <14t6hwu8udm8j$.1x339y69m2ew1.dlg@40tude.net> <14ay3vz2ngj9s.1bmilwgckl3lc$.dlg@40tude.net> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Message-ID: <491eb919$0$31346$9b4e6d93@newsspool4.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 15 Nov 2008 12:57:13 CET NNTP-Posting-Host: 2f59d30e.newsspool4.arcor-online.net X-Trace: DXC=;IY=YXKQ4>D78PK[oJ2ng@4IUK 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;