www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: How about 'pure' for constants?

reply Hxal <hxal freenode.d.channel> writes:
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.
Dec 12 2007
next sibling parent reply Gilles G. <schaouette free.fr> writes:
"alias" does not express the intent of the definition.
For example, when writing "alias foo = function int(int a, int b) {...};", the
fact that the function does not have side effects is not explicit.
The expressions
pure real pi=3.14159;
pure real A = area(real diameter);
are much more informative.

Hxal Wrote:

 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.

Dec 12 2007
parent Hxal <hxal freenode.d.channel> writes:
Gilles G. Wrote:

 "alias" does not express the intent of the definition.
 For example, when writing "alias foo = function int(int a, int b) {...};", the
fact that the function does not have side effects is not explicit.
 The expressions
 pure real pi=3.14159;
 pure real A = area(real diameter);
 are much more informative.

You're right, this one doesn't. A pure pragma suits function definitions a lot better though. I realized after I wrote the first suggestion that you can even write "pragma(pure) int foo (...) {}". As for using an alias declaration for constants, it's no less informative than a pure constant declaration, except it doesn't introduce a new keyword, nor does it reuse an existing one in a non-obvious way (enum).
Dec 12 2007
prev sibling parent reply Oskar Linde <oskar.lindeREM OVEgmail.com> writes:
Hxal wrote:
 Don Clugston Wrote:
 
 pure real pi = 3.141592564;
 ...
 pure int foo(int a, int b);


I don't think pure is the optimal solution, but it is much better than enum and I could definitely live with it.
 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;".

I agree. It feels like lately, the design of D has left that of the free outside-the-box thinker and attained a C++ mindset where simplicity and elegance is rendered irrelevant. I hope I am wrong. :) -- Oskar
Dec 13 2007
parent Sean Kelly <sean f4.ca> writes:
Oskar Linde wrote:
 
 It feels like lately, the design of D has left that of the free 
 outside-the-box thinker and attained a C++ mindset where simplicity and 
 elegance is rendered irrelevant. I hope I am wrong. :)

I think this is inevitable as the popularity of a language increases and breaking changes becomes less and less appealing. But I am hoping we can hold that day off as long as possible. Still the presence of things like foreach_reverse suggest that it may already be here ;-) Sean
Dec 13 2007