comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Question about default discriminants and mutable objects.
Date: Thu, 6 May 2010 17:15:24 +0200
Date: 2010-05-06T17:15:24+02:00	[thread overview]
Message-ID: <fmsppljh9dt9$.1ldlehd6kjbag$.dlg@40tude.net> (raw)
In-Reply-To: 4be20f28$0$2431$4d3efbfe@news.sover.net

On Wed, 05 May 2010 20:41:57 -0400, Peter C. Chapin wrote:

> I also understand that an instance of a type without default discriminants
> can't be mutated in this way (that is, by assignment).

You can assign it as a whole as well as its components individually. The
object is mutable, but you cannot change its constraint. Compare it with
similar cases::

   S : String := "abc";

Here the constraint is the array bounds. They cannot be changed, yet S is
mutable.

   T : Foo'Class := ...;

Here the constraint is the type tag. It cannot be changed, but T is
mutable.

> 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.

That is not a property of the type. It is of a type constraint. Type +
constraint = subtype. Ada is a bit sloppy in the object's subtype
specification. When you declare S as String you write a type, but the
compiler reads it as a constrained subtype of String. That is not good, but
it is difficult to propose a cure. Probably:

   S : String (<>);  -- Any subtype of String
   T : Foo'Class (<>); -- Any type from the class

etc.

> Furthermore one could imagine treating default discriminants as 100%
> syntactic sugar and not endowing them with any special semantics regarding
> mutability.

IMO, discriminant's defaults should imply nothing like what they do now.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



      parent reply	other threads:[~2010-05-06 15:15 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-06  0:41 Question about default discriminants and mutable objects Peter C. Chapin
2010-05-06  1:26 ` 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 [this message]
replies disabled

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