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-27 12:18:20 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!sn-xit-03!sn-xit-01!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: Fri, 27 Dec 2002 14:17:03 -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:32340 Date: 2002-12-27T14:17:03-06:00 List-Id: I think that for this proposal to get serious consideration, you'll have to give rules to plug the many holes in it: -- You'd need to carefully explain why solutions based on functions (as Nick Roberts described) are not sufficient; -- You'll need to explain how this works for controlled types (an incompatibility there is simply not going to be tolerated); -- You'll need to determine the rules for these in generics. Your current description would be a giant contract model violation, and that needs to be fixed. In particular, for a generic formal private type: generic type Priv is private; what 'Get_Constructor and 'Initialize routines can be called? The fact that these are different in profile is simply not going to fly here (and I doubt that banning the use of constructors in generic bodies is going to be an acceptable solution). -- You'll need to explain how this works in the face of disappearing components on an assignment. That has been the problem that has killed all previous proposals like this one. See http://www.adaic.org/standards/95aarm/html/AA-7-6.html, paragraphs 17.a-17.h for a discussion. I'd prefer making the function solution work. There is a proposal to make it possible to initialize limited objects with a function call, which would eliminate that objection. Your other objection: >The idea that a constructor is just a function is IMO badly wrong. Limited >types is just one example why. Another example is class-wide types. How to >construct a class-wide object from scratch? To write a class-wide function? >But then it will never ever dispatch. A dispatching one? But the type is >unknown and there is no object. This is why Ada's stream attributes are >made hard-wired. This is also why assignment is a problem. The bug, IMHO, is that you can't write T'Class'Input in Ada. Its terrible that magic is needed there, because its clear that there are other cases where that sort of code would be useful. We investigated some solutions to that problem in the past. The primary problem is how to get the object created for a particular value of Ada.Tags.Tag. A direct approach doesn't work, because you don't know how to initialize the discriminants (they can be different for extensions than for the base type). However, an approach based on using the tag value to control dispatching of a function (rather than a result object) does work. And it is very simple to implement (as compilers are essentially dispatching on a value of Ada.Tags.Tag anyway). However, most people thought that inventing syntax to solve this problem was too heavy, and there really isn't any alternative. So nothing much has been done on this problem. The basic idea is to somehow figure a value of Ada.Tags.Tag, then use it to control dispatching on a function that returns the correct kind of object. This requires a special call: Obj : T'Class := Func () use Tag_Value; With these two capabilities, I believe that functions provide appropriate constructors, and you don't necessarily need to use a 'handle' implementation. (I suspect that in practice, you often will want to use a handle implementation anyway, but I certainly agree that you shouldn't be forced into it.) Leveraging existing language features is far preferable to inventing a whole new mechanism. Randy Brukardt.