D const design rationale
Martin Howe
martinhowe at myprivacy.ca
Sat Jun 23 05:36:01 PDT 2007
"Reiner Pope" <some at address.com> wrote in message
news:f5ipqd$2m6j$1 at digitalmars.com...
> can we expect some annotation for functions which says 'this function
> doesn't read/write any global variables?'
Personally, I like the PHP way; each global variable must be declared as
such before use; the syntax is similar to a local variable. Any function
including any "global" declarations is thus "not pure".
....int b
....
....int foo()
....{
........global int b;
........
........b++;
........return b * 2;
....}
....
....int square(int x)
....{
........return x * x;
....}
....
....pure int baz()
....{
........return foo(); // fails: foo is impure (it has "global" declarations)
....}
....
....pure int bar(int x)
....{
........global int b; // fails: global conflicts with pure
........
........return x*(b++); // would fail
....}
More information about the Digitalmars-d
mailing list