Why is 'scope' so weak?

Lars T. Kyllingstad public at kyllingen.NOSPAMnet
Tue Nov 23 04:55:42 PST 2010


On Tue, 23 Nov 2010 13:46:19 +0100, Lutger Blijdestijn wrote:

> Lars T. Kyllingstad wrote:
> 
>> If I've understood things correctly, by marking a delegate parameter
>> with 'scope' you tell the compiler not to create a true closure for the
>> delegate.  Effectively you're saying "I promise not to escape this
>> delegate, so you don't need to copy its context to the heap".
>> 
>> In brief, my question is:  Why doesn't the compiler enforce this
>> promise?  In particular, why is 'scope' not a type constructor?
>> 
>> (Note that this is mostly a question out of curiosity, and not really a
>> proposal for a new feature.  I imagine it has been discussed in the
>> past and rejected for some reason.)
>> 
>> Considering that the compiler enforces proper use of pure, nothrow,
>> const, and all those other things, it doesn't seem much harder to do
>> the same with scope.
>> 
>> As an example, I really can't see a reason why obviously wrong code
>> like this should be allowed:
>> 
>>     void delegate() globalDg;
>> 
>>     void foo(scope void delegate() dg)
>>     {
>>         globalDg = dg;
>>     }
> 
> Most likely it is not yet implemented? It's hard to find something on
> this topic, I couldn't find anything in the spec or tdpl. I did found
> this one post by Andrei about your question:
> 
> http://permalink.gmane.org/gmane.comp.lang.d.concurrency/617

Thanks.  He only says that "...too many qualifiers make the language 
quite baroque."  Hopefully there is a better reason than that. ;)

-Lars


More information about the Digitalmars-d-learn mailing list