Manifest constants - why not 'alias' ?

Janice Caron caron800 at googlemail.com
Sat Dec 8 01:54:49 PST 2007


On 12/8/07, Walter Bright <newshound1 at digitalmars.com> wrote:
> Why isn't:
>         enum x = 3;
> more intuitive?

I didn't say it wasn't intutive. /Anything/ is intuitive, once you get
used to it, if the syntax is simple enough, and I can't argue that
this isn't simple.

I said it was the wrong word. "enum" is short for "enumeration". It
should be used for the purpose of enumeration, and nothing more.
Honestly, I wish D had /real/ enumerations, so you could do

    enum Col { red, orange, yellow, green, blue, indigo, violet };

to indiciate that Col was a type defining an ordered sequence of
symbols. It has a /first/ element (red), a last element (violet), a
successor/precedessor relationship (the successor of yellow is green),
and comparison functions whose meaning is "left of" and "right of".
Elements would have a toString() function, so that orange.toString ==
"orange". But what these beasts would NOT have any numerical
properties at all. Converting to or from int is just not possible. You
know - /proper/ enums! (Of course, that's not going to happen, so this
is not a feature request. The current implementation lets me /pretend/
that enums are proper enums, and that's probably good enough).

We all love the idea of compile-time constants. They're a /great/
idea. Just, please use the right word to express them. If you don't
like "final", not a problem. Others have suggested "alias", "macro",
"define" and "let", and any one of those would make me happy.



More information about the Digitalmars-d mailing list