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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,72c34c66b38e0e05 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-12-31 16:28:50 PST Path: archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-post-01!supernews.com!corp.supernews.com!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Proposal: Constructors, Assignment [LONG] Date: Tue, 31 Dec 2002 18:28:35 -0600 Organization: Posted via Supernews, http://www.supernews.com Message-ID: References: X-Newsreader: Microsoft Outlook Express 4.72.3612.1700 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3719.2500 X-Complaints-To: abuse@supernews.com Xref: archiver1.google.com comp.lang.ada:32421 Date: 2002-12-31T18:28:35-06:00 List-Id: 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 (); > >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.