How about 'pure' for constants?

Sean Kelly sean at f4.ca
Tue Dec 11 07:38:39 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);

I've been wondering the same thing, but couldn't decide if the keyword 
made sense in this context.  But by your explanation it clearly does. 
It has my vote.


Sean



More information about the Digitalmars-d mailing list