From: Adam Beneschan on
On May 5, 9:56 pm, AdaMagica <christoph.gr...(a)eurocopter.com> wrote:
> Gene,
> you guessed quite well. See Ada 83 Rationale
>
> http://archive.adaic.com/standards/83rat/html/ratl-04-07.html#4.7
>
> and especially 4.7.4.

I don't think that's a complete explanation, though. It doesn't
explain why you couldn't have (1) a discriminant type without a
default, in which the initial value of the discriminant must be
specified for each object but the discriminant could still be changed
by assigning the whole object; or (2) a discriminant type with a
default discriminant but where all objects of the type are still
constrained [thus making an object declaration X : T; equivalent to
X : T(default);]. It's probably the inability to do one or both of
those two things that causes the "annoyance" Randy mentioned.

As for why those possibilities couldn't be provided, it's probably
just because they would have had to come up with some funky syntax for
it. That's not a trivial consideration. Designing syntax is not
always easy.

-- Adam
From: Dmitry A. Kazakov on
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
From: Peter C. Chapin on
AdaMagica wrote:

> Gene,
> you guessed quite well. See Ada 83 Rationale
>
> http://archive.adaic.com/standards/83rat/html/ratl-04-07.html#4.7
>
> and especially 4.7.4.

Thanks... that was interesting. I suppose the next time I find myself
wondering about the rationale for a design decision in Ada I should maybe
read the rationale. :)

Peter

From: Randy Brukardt on
"Peter C. Chapin" <pcc482719(a)gmail.com> wrote in message
news:4be361f3$0$2430$4d3efbfe(a)news.sover.net...
> AdaMagica wrote:
>
>> Gene,
>> you guessed quite well. See Ada 83 Rationale
>>
>> http://archive.adaic.com/standards/83rat/html/ratl-04-07.html#4.7
>>
>> and especially 4.7.4.
>
> Thanks... that was interesting. I suppose the next time I find myself
> wondering about the rationale for a design decision in Ada I should maybe
> read the rationale. :)

Remember that there are three of them: one each for Ada 83, Ada 95, and Ada
2005. Depending on the feature, you might need to look at all three. (Not
sure if there will be one for Ada 2012.)

Randy.


From: Robert A Duff on
"Randy Brukardt" <randy(a)rrsoftware.com> writes:

> Remember that there are three of them: one each for Ada 83, Ada 95, and Ada
> 2005. Depending on the feature, you might need to look at all three. (Not
> sure if there will be one for Ada 2012.)

Right. Also, for very detailed design decisions, look at the AARM
for rationale. That's not available for Ada 83 -- I think
Jean Ichbiah was not a "detail man". ;-)

As to default discriminants causing mutable discriminants,
despite the rationale, it's a bad design. It's confusing.
And it means you can't use defaults just as defaults when
you want immutable discriminants. Except you CAN do
that for limited types (more confusion). And for '[in] out'
parameters, you don't know at compile time whether the
thing is mutable, which is just a tripping hazard.

Also, some compilers chose the deallocate/reallocate
strategy, and others chose the allocate-the-max
strategy. That's bad; it means you can't use the
feature portably. Standards are supposed to promote
uniformity.

- Bob