Re: [PHP-DEV] Closures and __FUNCTION__

2009-04-13 Thread Peter Danenberg
> function Y($F) { > $func = function ($f) { return $f($f); }; > return $func(function ($f) use($F) { > return $F(function ($x) use($f) { > $ff = $f($f); > return $ff($x); > }); > }); > } That's interesting;

Re: [PHP-DEV] Re: Closures and __FUNCTION__

2009-04-13 Thread Peter Danenberg
> First, we define $foo and load it with NULL so that it is available for > referencing. It turns out loading $foo is superfluous; I can get away with just: $foo = function($foo) use (&$foo) { $foo(); } > Next, in terms of program logic, we create a closure with a lexical > ('use') va

Re: [PHP-DEV] Re: Closures and __FUNCTION__

2009-04-13 Thread Peter Danenberg
Quoth Justin Martin on Pungenday, the 30th of Discord: > Apparently it works as such: > > $foo = NULL; > $foo = function($foo) use (&$foo) { > ... > } > > Still rather hackish, but better than globals I suppose? Heh; amazing. I'm not going to pretend to comprehend this hack; but I'll use i

Re: [PHP-DEV] Re: Closures and __FUNCTION__

2009-04-13 Thread Peter Danenberg
Quoth Justin Martin on Pungenday, the 30th of Discord: > If I recall correctly, you can use the 'use' keyword. Thanks, Justin; that occurred to me, too. But the following results in "Notice: Undefined variable: factorial": $factorial = function($n) use ($factorial) { if ($n == 1)

[PHP-DEV] Closures and __FUNCTION__

2009-04-11 Thread Peter Danenberg
The original anonymous functions patch[1] contained support for __FUNCTION__ as a recursion mechanism in closures, such that I should be able to do something like this: $factorial = function($n) { if ($n == 1) return 1; else return $n * call_user_func(__FUNCTION__, $n