From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,71dcb452eafb5045,start X-Google-Attributes: gid103376,public From: "Stanley R. Allen" Subject: Re: Ada enumerations Date: 1997/12/10 Message-ID: <348EDDC9.794B@hso.link.com>#1/1 X-Deja-AN: 296986871 Organization: NASA, Kennedy Space Center Newsgroups: comp.lang.ada Date: 1997-12-10T00:00:00+00:00 List-Id: Matthew Heaney wrote: > > > > function Value_List return Value_List_Type is > > Tmp : Value_List_Type (Enum'Pos (Enum'First) .. > > Enum'Pos (Enum'Last)); > > begin > If you really insist on such a function, then do this: > > generic > type Enum is (<>); > type Enum_Rep is range <>; > type Enum_Rep_Array is array (Natural range <>) of Enum_Rep; > function Value_List return Value_List_Type; This is certainly not a general solution. Don't forget: this is part of an interface to be used by dozens of programmers on a large project with various kinds of enumeration types. It's too much of a burden to make the users choose between two different generics to instantiate depending on whether their enum type has special representation or not. > No, Ada doesn't come with an attribute to return the representation of an > enumeration literal, because it doesn't need to! There are a number of features in Ada that you could argue with on this basis. Some of the features are included for convenience (like 'Max), completeness, or portability. My argument for an attribute like 'Representation (or 'Enum_Rep in GNAT) is based on these factors. At the risk of seeming shrill, I'll repeat myself: what good reason can there be for allowing me to *specify* enumeration representations but denying me the ability to easily *query* them also? > And besides, if you're converting between enumeration literals and > integers often, you probably shouldn't be using an enumeration type > anyway. Keep things simple, and use an integer type and associated > constants of that type. > I would take too long in this forum to explain the details, but note that working on a large project often leaves you without the luxury of making that choice. In my case, I am not the one who decides to "use an integer type and constants of that type" instead of a rep-spec'd enumeration type. The users of my interface make that kind of decision as part of their design process; it's my job to provide an interface that's general enough to support them, and simple enough to avoid complex programming on their part. -- Stanley Allen mailto:s_allen@hso.link.com