basic questions about enums and enum types

new topic     » topic index » view thread      » older message » newer message

Dear euphorians,

I would appreciate your guidance on some things about enums that confuse me.

I understand the basic notion of an enum as a collection of named constants, where the value of each element is 1 greater than the value of its predecessor, eg:
enum ONE, TWO, THREE, FOUR (where the value of the elements is 1, 2, 3, 4)?

And i understand the notion that an individual element may be assigned a particular value, from which point subsequent elements automatically increment, eg:
enum ONE, TWO, TEN=10, ELEVEN, SIX=6, NEXT (ie 1, 2, 10, 11, 6, 7)

Is it correct to think, then, that if there were no enums in OEu we would have to write a series of constants with the corresponding values
constant MONDAY = 1, TUESDAY = 2, WEDNESDAY = 3... etc?

Is it correct to consider enums as a construction that is quicker and easier to code than writing separate constants, and that makes our intention clearer by grouping a series of logically related values?

When it comes to enum types, is it correct to think of them as a mechanism for ensuring that only certain values for individual elements are valid? The reference manual gives an example:
enum type color RED=4, GREEN=7, BLACK=1, BLUE=3, PINK=10 end type

Is this simply a way for us to ensure that the valid value for RED ('positional value' = 1), is 4; for PINK ('positional value' = 5) is 10, etc? I haven't used this in code yet, and i don't see just at the moment how it would be useful, but i assume it must be or it wouldn't be there - true? A simple example might help me 'get it'.

I don't understand the subsequent example in the manual:
enum type color RED, GREEN=7, BLACK=1, BLUE=3, PINK=10 end type
The values of the elements are said to be 1, 2, 1, 4, 5 Why does the 'positional value' of BLACK go back to 1? Why not 3, since it is the third element along? Again, perhaps a simple example here, will help me understand the significance of this.

Thank you for your help. (And for those folks celebrating a festive season at the moment, i hope it is a safe and happy one.)

new topic     » topic index » view thread      » older message » newer message


Quick Links

User menu

Not signed in.

Misc Menu