comp.lang.ada
 help / color / mirror / Atom feed
From: "Yannick Duchêne (Hibou57)" <yannick_duchene@yahoo.fr>
Subject: Re: Why constant components are not permitted ?
Date: Fri, 25 Nov 2011 10:53:47 +0100
Date: 2011-11-25T10:53:47+01:00	[thread overview]
Message-ID: <op.v5hxrxupule2fv@douda-yannick> (raw)
In-Reply-To: 9j8sg4FfjuU1@mid.individual.net

Le Fri, 25 Nov 2011 07:56:03 +0100, Niklas Holsti  
<niklas.holsti@tidorum.invalid> a écrit:

> On 11-11-24 19:14 , David Sauvage wrote:
>> Hello,
>>
>> given the following :
>>
>> type Object is record
>>     Tag : constant String := "key"; -- GNAT compilation failed :
>> constant components are not permitted
>> end record;
>>
>> In my case I find it useful to declare my Object Tag component as a
>> constant, but it is not permitted, I would be interested to learn
>> why ?
>
> It seems no earlier responder has understood why you want to have a  
> constant component, nor do I, so I'll ask directly: Why do you think a  
> constant component would be  useful?
The same question for me. A record, is not an interface, that's an  
implementation solution. One want to use a record to store some aggregated  
stuff, thus its name, “record”.

If a type T is implemented as a record, the interface should not expose  
the record (as with any implementation details, except if part of an  
expected specification). If T is to be associated with a constant, the  
constant could be implemented as a function getting a T as parameter, and  
returning that constant.

Unless the OP was to reinvent a wheel already provided by Ada, which is  
record discriminant. If that constant is a kind of characterization of  
instances of T, then a discriminant is the obvious choice.

-- 
“Syntactic sugar causes cancer of the semi-colons.” [1]
“Structured Programming supports the law of the excluded muddle.” [1]
[1]: [Epigrams on Programming — Alan J. — P. Yale University]



  reply	other threads:[~2011-11-25  9:53 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-24 18:14 Why constant components are not permitted ? David Sauvage
2011-11-24 19:06 ` anon
2011-11-24 19:49   ` David Sauvage
2011-11-24 22:55     ` Georg Bauhaus
2011-11-24 23:53     ` anon
2011-11-24 19:46 ` Ludovic Brenta
2011-11-25  9:10   ` Dmitry A. Kazakov
2011-11-25 10:23     ` Ludovic Brenta
2011-11-25 10:45       ` Dmitry A. Kazakov
2011-11-25  6:56 ` Niklas Holsti
2011-11-25  9:53   ` Yannick Duchêne (Hibou57) [this message]
2011-11-25 10:06     ` AdaMagica
2011-11-25 10:16       ` AdaMagica
2011-11-25 10:56       ` Yannick Duchêne (Hibou57)
2011-11-25 17:41       ` Niklas Holsti
2011-11-26  0:23         ` anon
2011-11-29  4:10         ` Randy Brukardt
2011-11-29  7:55           ` David Sauvage
2011-11-29 10:55             ` Yannick Duchêne (Hibou57)
2011-11-29 11:17             ` Mark Lorenzen
2011-11-26 10:22       ` Pascal Obry
2011-11-26 10:59         ` Dmitry A. Kazakov
2011-11-25  7:03 ` AdaMagica
2011-11-25  9:12 ` Dmitry A. Kazakov
2011-11-25  9:57   ` Yannick Duchêne (Hibou57)
2011-11-25 10:22     ` Dmitry A. Kazakov
2011-11-25 11:00       ` Yannick Duchêne (Hibou57)
replies disabled

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