Manifest constants (was const again)
Bill Baxter
dnewsgroup at billbaxter.com
Fri Dec 7 21:43:41 PST 2007
Walter Bright wrote:
> Oskar Linde wrote:
>> Like others, I propose that manifest constants use the alias keyword.
>> Alias is perfect for this.
>
> alias does make sense up to a point, and that point is:
>
> alias int x = 3;
>
> That makes no sense in the light of what alias currently does.
Is there some reason why it matters what alias currently does? I think
this is why most people here are disagreeing with you about using
"enum". You seem to be looking from the language implementer's point of
view and saying "which chunk of code do I have already implemented that
would be easiest to change into something supporting manifest
constants?". Whereas most of us are looking at the *words* and saying
"which of these words best describes what we're trying to do?"
Supporting alias int x = 3 may be more difficult to implement than
enum int x = 3 because it changes the role of alias. But users of the
language don't care. It still makes perfect sense in terms of what
'alias' *means*. x becomes an alias for the literal '3'. You can think
of it as meaning
alias x = cast(int)3;
but who wants to type that? Since x will become something that acts a
lot like an int variable, it makes sense to allow the use of the
familiar "int x" declaration as well.
> Manifest
> constants are not untyped, although their type can often be inferred
> from their initializer, just like auto declarations.
So alias x = 3 should work too, and probably be a polysemous constant
when those exist. I don't see a problem there.
--bb
More information about the Digitalmars-d
mailing list