From: | Gene <gene.ressler@gmail.com> |
Newsgroups: | comp.compilers |
Date: | Mon, 27 Dec 2010 07:58:42 -0800 (PST) |
Organization: | Compilers Central |
References: | 10-12-046 |
Keywords: | design, storage |
Posted-Date: | 28 Dec 2010 18:09:12 EST |
True. And the ability to trivially extend types by adding an enumerated set
of additional values would IMO be a good feature. For example, extension with
a value "Unknown" would obviate varied ad hoc idioms: null pointers, parallel
return values, etc. To bring this back to the variant records topic, I often
encounter needs for types like
type Possibly_Valid_Float(Valid : Boolean := False) is
record case Valid of
when True => Value : Float;
when False => Null;
end record;
and then replace Float with any other type. But the syntax for setting and
using these is of course completely different from that needed for Float.
Much nicer would be
type Possibly_Valid_Float is new Float with (Unknown);
X, Y : Possibly_Valid_Float := 0.0;
function "/" (Num, Den : Possibly_Valid_Float)
return Possibly_Valid_Float is
begin
if Num = Unknown or Den = Unknown then
return Unknown;
end if;
return X / Y;
exception
when others => return Unknown;
end;
Etc...
Merry Christmas, all.
Return to the
comp.compilers page.
Search the
comp.compilers archives again.