Re: language design implications for variant records in a pascal-like language

Gene <gene.ressler@gmail.com>
Mon, 27 Dec 2010 07:58:42 -0800 (PST)

          From comp.compilers

Related articles
language design implications for variant records in a pascal-like lang noitalmost@cox.net (noitalmost) (2010-12-22)
Re: language design implications for variant records in a pascal-like gneuner2@comcast.net (George Neuner) (2010-12-23)
Re: language design implications for variant records in a pascal-like danielzazula@gmail.com (Daniel Zazula) (2010-12-24)
Re: language design implications for variant records in a pascal-like bobduff@shell01.TheWorld.com (Robert A Duff) (2010-12-24)
Re: language design implications for variant records in a pascal-like mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2010-12-25)
Re: language design implications for variant records in a pascal-like DrDiettrich1@aol.com (Hans-Peter Diettrich) (2010-12-25)
Re: language design implications for variant records in a pascal-like gene.ressler@gmail.com (Gene) (2010-12-27)
Re: language design implications for variant records in a pascal-like bobduff@shell01.TheWorld.com (Robert A Duff) (2010-12-27)
Re: language design implications for variant records in a pascal-like noitalmost@cox.net (noitalmost) (2010-12-27)
Re: language design implications for variant records in a pascal-like cr88192@hotmail.com (BGB) (2010-12-27)
Re: language design implications for variant records in a pascal-like bobduff@shell01.TheWorld.com (Robert A Duff) (2010-12-28)
Re: language design implications for variant records in a pascal-like mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2010-12-29)
Re: language design implications for variant records in a pascal-like bc@freeuk.com (BartC) (2010-12-29)
[49 later articles]
| List of all articles for this month |
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.


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.