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-Thread: 103376,2e2db8edf2656165 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.megapath.net!news.megapath.net.POSTED!not-for-mail NNTP-Posting-Date: Wed, 28 Sep 2005 19:08:54 -0500 From: "Randy Brukardt" Newsgroups: comp.lang.ada References: <1lw8oz33ao529.12ep5ay7rg4oc$.dlg@40tude.net> <5-GdnRjCgYZOfKneRVn-qw@megapath.net> <3dachnu33lly.fpr0wvf6nj05$.dlg@40tude.net> Subject: Re: Constructing an object Date: Wed, 28 Sep 2005 19:12:40 -0500 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4952.2800 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4952.2800 Message-ID: NNTP-Posting-Host: 64.32.209.38 X-Trace: sv3-3sn5gXzb6C1uA677QQqkTssrR8BcvT3YYqfl75CIArnpI0zuQGeyxbTbZV+D1mprgn4759Kxn4SQVrG!C46fCXrh827c81uLCVUonLE53rmxAxyaWq+DRfHFVUbIfFToyrRkBNjEmlQttr6U7FgKP4+Lr9ND X-Complaints-To: abuse@megapath.net X-DMCA-Complaints-To: abuse@megapath.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.32 Xref: g2news1.google.com comp.lang.ada:5260 Date: 2005-09-28T19:12:40-05:00 List-Id: "Dmitry A. Kazakov" wrote in message news:3dachnu33lly.fpr0wvf6nj05$.dlg@40tude.net... > On Sat, 24 Sep 2005 00:23:01 -0500, Randy Brukardt wrote: > > > In Ada 200Y, access discriminants are allowed on nonlimited > > types, but they then cannot have defaults (such discriminants cannot change > > after object creation, and we needed to disallow changing them via > > assignment). > > How? The type should be then abstract or unconstrained and the user should > have rather its subtype with the discriminant limited to the value. If the discriminants don't have defaults, the type *is* unconstrained. The user has to provide the discriminant value with the object declaration or initial value, or from a subtype declaration that is then used to create object. > > You also failed to mention that the object factory can be implemented > > (probably *ought* to be implemented) with the Ada 200Y > > Generic_Dispatching_Constructor. That takes a tag value and a dispatching > > function and creates an appropriate object for the tag, initialized by the > > dispatching function. > > That is a good news, though it still looks like hack. It *is* a hack! A hack is better than the Ada 95 situation (no way to do it). The whole idea is simply to provide a way to make the mechanism that compilers have visible to the user. > Generics is used to > pass the parameters, instead of providing some native mechanism for > determining the tag, discriminants, bounds and other constraints. We tried a lot of those, but they all fail because Ada allows discriminants on tagged types. That makes it necessary for the user code to create the object; doing the operations separately is not an option. The only thing that I know *would* work (new syntax to allow dispatching on a provided tag value) was considered way too heavyweight for a relatively minor problem. > One > possibility could be to have for each type a predefined null-record type > having the same discriminants (tag and bounds are mapped to discriminants). > Then the object of this type could be passed to the allocator. What allocator? The critical part of the whole scheme is that there is no allocator required; this works just as well on stack objects as it does on heap-allocated objects. It should never be necessary to use heap-allocated objects (or syntax like 'Access and .all) to get the benefits of O-O design. > IMO there should be proper constructors for all types. Constructing > functions are too error-prone. No one agreed with that. The only problem with using functions for constructors was the weird semantics for limited types, which was solved by getting rid of those semantics. If you want to ensure that constructor functions are used, you need to declare your types with (<>) discriminants. > Further, Ada needs extensible primitive and > class-wide operations, that could finally solve the construction / > assignment problem. I have no idea what this means; Ada has extensible primitive operations (indeed, *only* primitive operations can be extended). Randy.