Whoa, now that was a good entry for the next obfuscated Pike contest. :)
I take it that it's some kind of cheating to simply give a name to a lambda?
function Y (function f) { mixed g (mixed... args) { return f (g, @args); }; return g; }
/ Martin Stjernholm, Roxen IS
Previous text:
2003-10-06 09:25: Subject: Re: Some tasks from the conference
o Implement this_function().
to add to the discussion, (what i learned at the conference) this_function() is mostly usefull in hilfe-like situations,
I guess this is the computer science way of defining this_function:
function fac = Y (lambda (function this_function, int x)
{ return (x == 0) ? 1 : x * this_function(x - 1); });
Result: `()
fac(17);
Result: 355687428096000
All you need is to first define this general but strange-looking function:
function Y(function f)
{ return lambda(mixed y) { return (lambda(function x, mixed w) { return f(lambda(mixed z) { return x(x, z); }, w); }) (lambda(function x, mixed w) { return f(lambda(mixed z) { return x(x, z); }, w); }, y); }; }
It took me quite a while to try to remember what the function looks like, and then write it in pike ;-)
/ Niels Möller (igelkottsräddare)