preparing for const, final, and invariant

Bruno Medeiros brunodomedeiros+spam at com.gmail
Sat May 26 08:09:56 PDT 2007


I've only now been able to read this thread, so, just some simple questions:

Walter Bright wrote:
> This is coming for the D 2.0 beta, and it will need some source code 
> changes. Specifically, for function parameters that are arrays or 
> pointers, start using 'in' for them.
> 
> 'in' will mean 'scope const final', which means:
> 
> final - the parameter will not be reassigned within the function
> const - the function will not attempt to change the contents of what is 
> referred to
> scope - the function will not keep a reference to the parameter's data 
> that will persist beyond the scope of the function
> 

Does this mean you have finished a working design for 
const/final/invariant/etc. ? If so, then what is the type of fooptr here? :
   final foo;
   auto fooptr = &foo;

> For example:
> 
> int[] g;
> 
> void foo(in int[] a)
> {
>     a = [1,2];    // error, a is final
>     a[1] = 2;   // error, a is const
>     g = a;    // error, a is scope
> }
> 
> Do not use 'in' if you wish to do any of these operations on a 
> parameter. Using 'in' has no useful effect on D 1.0 code, so it'll be 
> backwards compatible.
> 
> Adding in all those 'in's is tedious, as I'm finding out :-(, but I 
> think the results will be worth the effort.

Whoa there, that idea of 'scope' being the default togheter with 'const' 
and 'final', where did that came from? I understand why (and agree) that 
'final' and 'const' should be the default type modifiers for function 
parameters, but why 'scope' as well?

-- 
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d-announce mailing list