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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,72c34c66b38e0e05 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-01-01 06:13:25 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!proxad.net!freenix!deine.net!fu-berlin.de!uni-berlin.de!dialin-145-254-037-040.arcor-ip.NET!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Proposal: Constructors, Assignment [LONG] Date: Wed, 01 Jan 2003 15:13:44 +0100 Organization: At home Message-ID: References: Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: dialin-145-254-037-040.arcor-ip.net (145.254.37.40) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: fu-berlin.de 1041430403 10813935 145.254.37.40 (16 [77047]) User-Agent: KNode/0.7.1 Xref: archiver1.google.com comp.lang.ada:32432 Date: 2003-01-01T15:13:44+01:00 List-Id: Randy Brukardt wrote: > 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). I see, the old FORTRAN's idea to expose the result as a variable! I am very impressed, that such a thing managed to come through. (:-)) I suppose it will be allowed for all types? Then it would be interesting to know how it will work with by-value types: function Set_Bit (Value : Boolean) return Boolean is Result : return Boollean := Value; begin return Result; end Set_Bit; ... provided that the result is an element of a packed array. Somehow, somewhere the "in-place" requirement have to be relaxed. I wonder how many pages one will add to RM. Then there will be much work required to deal with things like: function Make_Session (Count: Integer) return Internet_Session is begin declare Result1 : return Internet_Session (24); begin if ... then return Result1; end if; end; declare Result2 : return Internet_Session (1000); - another size begin if ... then return Result2; end if; end; declare Result3 : Internet_Session (10); -- I forgot "return" begin return Result3; end; end Make_Session; I am not sure, but to determine whether there is only one result, could be equivalent to halting problem. So some sort of run-time support will be well required to determine this. Or will it be classified as one more bound error? >>... >>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.) Yes, this is why my proposal offers a way to write things working like T'Class'Input. When T'Class is created it (1) calls a user-defined function to determine Tag, then (2) it dispatches to a user-defined function to get constraints and finally (3) it dispatches to a user-defined Initialize. As I understood from your and other's responses the new call syntax "Func (...) use Tag" would give 1. 2-3 would be covered by new "FORTRAN" functions and an ability to "assign" what cannot be assigned. So there indeed will be a way to write Construct_Class without a case statement: function Construct_Class (...) return T'Class is begin -- figure out the tag declare Result : return T'Class := Construct_Object (...) use ; begin retrun Result; end; end Construct_Class; function Construct_Object (...) return T is begin -- figure out the discriminants declare Result : return T := T (); begin -- initialize other Result's fields retrun Result; end; end Construct_Object; Formally it should work. (?) -- Regards, Dmitry A. Kazakov www.dmitry-kazakov.de