2008/6/18 Gwynne Raskind <[EMAIL PROTECTED]>:

> On Jun 18, 2008, at 2:36 AM, Alexey Zakhlestin wrote:
>
>> 1) I am not sure that the current semantics of the "lexical" keyword is
>>> great in all cases. Is the reason why you don't allow by-value binding so
>>> that we don't have to manage more than one lambda instance per declaration?
>>>
>> by-reference binding is much closer to other languages symantics. I
>> guess, that was the main reason Christian chose it.
>> "by-value" may still exist, if people find, that they need it, but
>> only in addition, please.
>>
>> lambda has to reflect changing state of context, to be truly useful
>>
>
> In Lua, the language in which I've seen the most of closures and lambda,
> lexical scoping is handled this way:
>
> someVariable1 = "asdf";
> someVariable2 = "jkl;";
> SomeFunction = function()
>        local someVariable2 = "1234";
>
>        print someVariable1.." "..someVariable2.."\n";
> end
> print gettype(SomeFunction).."\n";
> SomeFunction();
> someVariable1 = "qwer";
> someVariable2 "0987";
> SomeFunction();
>
> The resulting output of this code fragment would be:
> function
> asdf 1234
> qwer 1234
>
> The Lua interpreter handles this by resolving variable references as
> they're made; "someVariable1" is looked up in the closure's scope and not
> found, so the interpreter steps out one scope and looks for it there, repeat
> as necessary. Once found outside the closure's scope, something similar to
> the proposed "lexical" keyword happens. Closures and lexical variables can
> be nested this way, to the point where a single variable in a sixth-level
> closure could still have been originally found in the global scope.
>
> I'm not sure this would work for PHP, I'm curious what others think.
>
> Of course, that fragment does a very poor job of showing off the extreme
> flexibility of Lua with regards to functions and scoping, but hopefully it
> illustrates the concept.
>
> -- Gwynne, Daughter of the Code
> "This whole world is an asylum for the incurable."
>
>
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Is "nested scope" just the same as "namespace" in this regard?



-- 
-----
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"

Reply via email to