Enumerated types_(re)
Mon, 09 Jun 1997 20:07:07 +0200
Phil Nelson wrote:
> =
> >type TComparisonResult=3D(Less value -1, Equals, Greater, Strange valu=
e 10);
> >
> >i.e. Ord(Less)=3D-1, Ord(Equals)=3D0, Ord(Greater)=3D1, Ord(Strange)=3D=
10.
> =
> Another problem ... it will make pred() and succ() harder if they must
> do succ(Greater) =3D> Strange and pred(Strange) =3D> Greater. I think =
> setting the initial value would be reasonable, but not allowing a
> jump in the values.
Only allowing to set the initial offset would make this kind of fetaure
useless. Implementing succ and pred functions using a simple table will
not cause much trouble.
=
Imagine this (for me very actual) problem:
Type assembler_instructions =3D ( add_x, sub_y, mul_a_x) ; =
(* course more complex*)
register_type =3D ( ax, bx, dx, bc, de, hl );
objectfile =3D record =
ai : assembler_instruction;
p1, p2 : register_type;
end;
(* using some ada-style for making the example *)
=
for assembler_instructions use =
( add_x =3D> 27, =
sub_y =3D> 37,
mul_a_x =3D> 127);
for register_type use
( ax =3D> 12,
bx =3D> 22, =
dx =3D> 32,
bc =3D> 01,
de =3D> 17,
hl =3D> 33);
The ord-function will, assuming you order the register-names in a simple
index only cause code to extract the real ord number from a table, i.e. =
ord_values : array (.enumeration_type.) of integer; =
(* the array keeping the values*)
Just suggesting :)
/Jakob :)
mailto:Jakob.Heinemann@ericsson.com
Ericsson Saab Avionics AB Link=F6ping
+46 13 284249
Jakob Heinemann (Jakob.Heinemann@ericsson.com)
HTML conversion by Lluís de Yzaguirre i Maura
Institut de Lingüística Aplicada -
Universitat "Pompeu Fabra"
e-mail: de_yza@upf.es