How about 'pure' for constants?

Don Clugston dac at nospam.com.au
Tue Dec 11 00:33:40 PST 2007


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);



More information about the Digitalmars-d mailing list