How about 'pure' for constants?
Craig Black
cblack at ara.com
Tue Dec 11 07:42:46 PST 2007
"Don Clugston" <dac at nospam.com.au> wrote in message
news:fjli16$1efd$1 at digitalmars.com...
> IIRC, there was a suggestion at the conference that D would get a new
> reserved word, 'pure', for functional programming. This should be
> considered as an alternative to 'enum'. I really don't like the idea of
>
> enum SomeEnormousStruct a = SomeFunction(AnotherEnormousStruct(x, "abc"));
>
> (and my CTFE code is already full of this sort of thing. It's simply not
> true that 'enums' would mostly be integral types).
>
> Seems to fit with the idea of 'having no side-effects' - a pure value
> would not be stored anywhere, and make no contribution to the size of the
> executable.
>
> pure real pi = 3.141592564;
>
> // this is really silly if you use 'enum' instead.
> pure real myNaN = real.nan;
>
> BTW, a pure function taking only pure parameters returns a pure value, so
> this seems to be entirely consistent:
>
> pure int foo(int a, int b);
Much better than enum. Thanks Don.
More information about the Digitalmars-d
mailing list