const, final, scope function parameters

Regan Heath regan at netmail.co.nz
Sun May 27 13:27:58 PDT 2007


Walter Bright Wrote:
> Frank Benoit wrote:
> > Perhaps we look at it from the wrong side.
> > 
> > If we want to change the D language to make it more const, the keywords
> > 'const', 'invariant'... are probably the wrong choice.
> > 
> > How about restricting keywords and add their opposites: 'mutable',
> > 'once' (write once) and then make every variable declaration const by
> > default? Each variable/parameter needs to be made modifyable with
> > modifiers if needed.
> 
> I think having to write:
> 
> 	mutable int x;
> 
> instead of:
> 
> 	int x;
> 
> just isn't going to please people.

Ahhh, I think I see what you're concerned about.  As in this example?

mutable int gx;
void foo(int y) {  //y is scope const final
  mutable int z;
}

where the global and local scope ints 'gx' and 'z' are not supposed to be const scope final.

Why can't we apply 'scope const final' to function parameters only?

In fact, that's what I was proposing when I said implicit 'in' should be 'const scope final'.  Global and local scope variables are not 'in' therefore are not 'const scope final'.

Regan Heath



More information about the Digitalmars-d mailing list