How about 'pure' for constants?

Hxal hxal at freenode.d.channel
Wed Dec 12 12:12:42 PST 2007


Don Clugston Wrote:

> pure real pi = 3.141592564;
> ...
> pure int foo(int a, int b);

Greetings fellow D community members. (since this is my first post.)

I'm not terribly fond of either the enum or the pure idea.

Perhaps this discussion is the perfect opportunity to revise the use of alias
declarations. Suppose we changed the alias syntax to the form of "alias x = y;"
We could amend its semantics to allow aliasing of values which would give us
what this discussions seems to be about - named values taking no memory space.

If we wanted to be able to specify the type we could further change the syntax
to either "alias optionaltype x = y;" or "optionaltype alias x = y;".

As far as pure functions go I guess the new alias could enable declaring a named
function literal: "alias foo = function int(int a, int b) {...};";
however I'd like to turn the attention of the community to the nifty pragma
statement, which I find underused. Pragmas can be an excellent way to provide
hints to the compiler without introducing new syntax, ie:
pragma (pure, functionname);
pragma (inline, functionname);
or even pragma (pure); inside the function body.

PS. My fondness of pragmas comes from my Ada programming background.




More information about the Digitalmars-d mailing list