Confusion about dynamically and lexically scoped closures

ParticlePeter via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Nov 8 15:08:04 PST 2015


Hi,
the confusion starts here: http://dlang.org/function.html#closures
End of paragraph bellow the last delegate example:
"This combining of the environment and the function is called a 
dynamic closure."

While according to 
https://en.wikipedia.org/wiki/Scope_%28computer_science%29
"Lexical scope vs. dynamic scope" I would call D delegates 
lexical closures, as the scope of the callee (scope where callee 
is defined) is used for free variable lookup, isn't that right?

Confusion is enhanced with this Dlang wiki: 
http://wiki.dlang.org/Function_literals
"This has brought up the specter of Dynamic Closures. The nested 
and/or anonymous functions can only access dynamic scope, which 
means scope that exists on the stack at the time of execution. 
This differs from lexical scope, which refers to the scope as 
indicated by the program text structure."

So what's what now?

Cheers, ParticlePeter


More information about the Digitalmars-d-learn mailing list