From: eachus@spectre.mitre.org (Robert I. Eachus)
Subject: Re: private type discriminants ignored?
Date: 1998/05/06
Date: 1998-05-06T00:00:00+00:00 [thread overview]
Message-ID: <EACHUS.98May6164528@spectre.mitre.org> (raw)
In-Reply-To: 6ib6t4$63f$1@goanna.cs.rmit.edu.au
In article <6ib6t4$63f$1@goanna.cs.rmit.edu.au> Dale Stanbrough <dale@goanna.cs.rmit.edu.au> writes:
> It seems from the preceeding set of rules about discriminants that
> they too are a complicated morrass. Are discriminants really that
> useful to be worth the effort? I look at all the rules (in the LRM)
> for them, and the code in Gnat, and it seems there is a lot of work
> trying to get them right. Perhaps I don't write the sort of code
> that they were intended to make simple, but I've rarely found them
> that useful.
There are several different cases that individually very useful.
For example, record types containing arrays whose bounds depend on a
discriminant with defaults. (Whew!) We really need a name for those.
They allow you to create types which correspond to char(N) varying in
PL/I:
subtype Index is Integer range 0..100;
type VString(Size: Index := 0) is record
Value: String(1..Size);
end record;
Objects of type VString can contain strings of different sizes:
V: VString;
...
V := (6,"String");
V := (27, "This is a test of VStrings.")
Of course, instead of counting and using aggregates, you provide
operations for the type that do all that for you:
V := + "This is a much longer string to assign to V.";
By the way, in Ada 95, there is a package for varying strings.
But 1) the above allows the package body to be written in Ada. and
2) you occaisionally need this feature for types other than
strings.
--
Robert I. Eachus
with Standard_Disclaimer;
use Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...
next prev parent reply other threads:[~1998-05-06 0:00 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <Es7569.4n2@world.std.com>
1998-04-24 0:00 ` private type discriminants ignored? Jay Sachs
1998-04-24 0:00 ` Joel VanLaven
[not found] ` <Es3A4J.Ion@world.std.com>
1998-04-28 0:00 ` Samuel T. Harris
1998-04-28 0:00 ` Patrick D. Rogers
1998-04-28 0:00 ` Samuel T. Harris
1998-04-30 0:00 ` Anonymous
[not found] ` <6ib6t4$63f$1@goanna.cs.rmit.edu.au>
1998-05-06 0:00 ` Robert I. Eachus [this message]
1998-05-01 0:00 ` Samuel T. Harris
[not found] <matthew_heaney-ya023680003004981720560001@news.ni.net>
1998-05-01 0:00 ` Anonymous
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox