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.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,31465939d9bd22cc X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!d39g2000yqa.googlegroups.com!not-for-mail From: Gene Newsgroups: comp.lang.ada Subject: Re: Question about default discriminants and mutable objects. Date: Wed, 5 May 2010 21:07:30 -0700 (PDT) Organization: http://groups.google.com Message-ID: <866a9a72-1f76-480d-b860-57e66ae155c0@d39g2000yqa.googlegroups.com> References: <4be20f28$0$2431$4d3efbfe@news.sover.net> NNTP-Posting-Host: 74.44.132.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1273118850 30314 127.0.0.1 (6 May 2010 04:07:30 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 6 May 2010 04:07:30 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: d39g2000yqa.googlegroups.com; posting-host=74.44.132.122; posting-account=-BkjswoAAACC3NU8b6V8c50JQ2JBOs04 User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB7.0 (.NET CLR 3.5.30729) GTBA,gzip(gfe) Xref: g2news2.google.com comp.lang.ada:11323 Date: 2010-05-05T21:07:30-07:00 List-Id: On May 5, 8:41=A0pm, "Peter C. Chapin" wrote: > Hopefully I can ask this question clearly... > > I understand that an instance of a type with default discriminants can be > mutated (here I mean have its discriminant changed) via assignment. It se= ems > like the most effective way for a compiler to support that ability is to > always allocate enough memory for the object to account for all possible > discriminant values. Mordechai Ben-Ari pretty much says this explicitly i= n > his book "Ada for Software Engineers." > > I also understand that an instance of a type without default discriminant= s > can't be mutated in this way (that is, by assignment). If a new value is > assigned to the object with the wrong discriminant the result is > Constraint_Error. This would allow the compiler to allocate just the memo= ry > necessary for that particular discriminant value used to initialize the > object since there would never be a (successful) attempt to stuff a large= r > object into that space. > > It seems like conceptually the issue of default discriminants and mutabil= ity > (in the sense I mean here) are independent. One could imagine some curren= tly > non-existent syntax that would allow the programmer to mark a type > declaration so that the compiler allowed discriminant values to be change= d > via assignment without leaning on the mechanism of default discriminants. > Furthermore one could imagine treating default discriminants as 100% > syntactic sugar and not endowing them with any special semantics regardin= g > mutability. > > Okay, so my question is: what was the rationale behind combining the noti= on of > default discriminants with the notion of mutability? Is there some subtle > technical reason why they must go together? I don't have pressing need to > know... I'm curious and I'm trying to deepen my understanding of this top= ic. > I don't have any special knowledge, and I also believe there is no really good reason for the connection. But I've always satisfied my own curiosity about this with the rationale that it's all about declarations that look like x : Foo; where Foo is a discriminated type. For Foo to be well-defined, it must have a default descriminant value. Otherwise it is no type at all. Yet the syntax here connotes that any value of type Foo ought to be assignable to x in the future. It would be an opaque gotcha if a future assignment to x with a value having other than the default discriminant caused a run-time exception. The conclusion is that x ought to be mutable. Viola! Discriminated types with default discriminant values are mutable. And if you're going to admit non-mutable discriminant types at all, then it's something like logical for all the rest to be these. Tortured, I agree... One can almost hear the design-by-committee in progress.