comp.lang.ada
 help / color / mirror / Atom feed
From: "Peter C. Chapin" <pcc482719@gmail.com>
Subject: Question about default discriminants and mutable objects.
Date: Wed, 05 May 2010 20:41:57 -0400
Date: 2010-05-05T20:41:57-04:00	[thread overview]
Message-ID: <4be20f28$0$2431$4d3efbfe@news.sover.net> (raw)

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 seems
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 in
his book "Ada for Software Engineers."

I also understand that an instance of a type without default discriminants
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 memory
necessary for that particular discriminant value used to initialize the
object since there would never be a (successful) attempt to stuff a larger
object into that space.

It seems like conceptually the issue of default discriminants and mutability
(in the sense I mean here) are independent. One could imagine some currently
non-existent syntax that would allow the programmer to mark a type
declaration so that the compiler allowed discriminant values to be changed
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 regarding
mutability.

Okay, so my question is: what was the rationale behind combining the notion 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 topic.

Thanks!

Peter




             reply	other threads:[~2010-05-06  0:41 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-06  0:41 Peter C. Chapin [this message]
2010-05-06  1:26 ` Question about default discriminants and mutable objects Randy Brukardt
2010-05-06  4:07 ` Gene
2010-05-06  4:56   ` AdaMagica
2010-05-06 14:59     ` Adam Beneschan
2010-05-07  0:47     ` Peter C. Chapin
2010-05-07  2:07       ` Randy Brukardt
2010-05-07 12:35         ` Robert A Duff
2010-05-06 15:15 ` Dmitry A. Kazakov
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox