Function scope arguments

deadalnix deadalnix at gmail.com
Tue Jan 15 01:50:53 PST 2013


On Monday, 14 January 2013 at 17:52:32 UTC, bearophile wrote:
> Maybe this thread shows the need for some design work, see the 
> comments by Hara:
>
> http://d.puremagic.com/issues/show_bug.cgi?id=8695
>
> What's the meaning of "in" function arguments? What are the 
> purposes of "scope" for function arguments that contain 
> indirections, and how to implement that?
>
> Bye,
> bearophile

Well I think about it a lot, it is unclear what is the solution, 
but here is how I see it :

stack variable as marked as local.

value marked local are considered scope in any inner scope.
values marked local can be passed to function by value or via 
scope argument.
values marked scope can be passed to function by value or via 
scope argument.

void foo() {
     int a; // a is local.

     {
         // a is scope here
     }
}

Everything accessed throw a scope value is scope.
scope are not referable throw any non scope.
local are not referable to scope.

each scope declaration introduce a new scope. different scope can 
never refers each others.

void foo(scope A a, scope B b) {
     // a and b are in different scopes.
     a.memeber; // Is in the same scope as a, but not as b.

     C c; // c is local.
     D d; // ditto.

     {
         // c and d are in the same scope. a and b are in 
different scope.
         c.member = d; // OK
         c.member = a; // Error.
     }
}

I still have some trouble to figure out the proper definition of 
it. And what can't be defined clearly is probably not understood 
enough to create a feature.


More information about the Digitalmars-d mailing list