comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R. Carter" <spam@spam.com>
Subject: Re: Correct use of variants
Date: Mon, 07 Nov 2005 19:46:26 GMT
Date: 2005-11-07T19:46:26+00:00	[thread overview]
Message-ID: <maObf.1054$Id6.73@newsread1.news.pas.earthlink.net> (raw)
In-Reply-To: <dknag1$2u3$1@sunnews.cern.ch>

Maciej Sobczak wrote:
> 
> What is the correct way to achieve the declaration of A with the 
> possibility of changing the discriminant later? One of the ways is to 
> use *some* default value for the discriminant, but I might have 
> difficulty deciding which value is better than the others for this role. 
> An arbitrary choice would create a misleading message to the reader that 
> the particular value is considered to be "best" or "idle" or "starting" 
> or whatever. In addition, having a default value for the discriminant 
> means that it's not obligatory to initialize the variable A while it's 
> declared and I would like to keep this enforced.

Note that having a non-defaulted discriminant does not require initialization:

A : Discriminated (Which => First);

There was a thread on here a while ago about requiring and enforcing 
initialization; you might want to search for it. The options included using 
unknown discriminants with an initializing function; using a controlled type; 
and using a private type with a default initialized field that indicates that 
the object has not been initialized, an operation that initializes objects of 
the type and indicates that they have been initialized, and all other operations 
raising an exception if the value indicates a lack of initialization.

-- 
Jeff Carter
"Sir Lancelot saves Sir Gallahad from almost certain temptation."
Monty Python & the Holy Grail
69



  parent reply	other threads:[~2005-11-07 19:46 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-07 10:32 Correct use of variants Maciej Sobczak
2005-11-07 12:52 ` Jean-Pierre Rosen
2005-11-07 19:46 ` Jeffrey R. Carter [this message]
2005-11-07 23:40 ` Stephen Leake
2005-11-08  8:40   ` Maciej Sobczak
replies disabled

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