How about 'pure' for constants?
Robert Fraser
fraserofthenight at gmail.com
Tue Dec 11 13:46:47 PST 2007
Don Clugston wrote:
> 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);
Hmmm... It's not a bad idea, but (like with enum & final), this worries me:
pure
{
int x = 5; // Manifest Constant
void func() { } // Function without side effects
}
More information about the Digitalmars-d
mailing list