Instantly share code, notes, and snippets.

@myw /ycomb.m
Created Apr 25, 2012

Embed
What would you like to do?
Anonymous Y Combinator Factorial Example in Matlab
Y = @(f) ...
feval( ...
@(x) f(@(v) feval(feval(x, x), v)), ...
@(x) f(@(v) feval(feval(x, x), v)));
if_ = @(pred, iftrue, iffalse) ...
[ arrayfun(@(~) iftrue(), zeros( pred())) ...
arrayfun(@(~) iffalse(), zeros(~pred())) ];
then_ = @(x) x;
else_ = @(x) x;
fct = @(f) @(n) ...
if_(@() n > 0, ...
then_(@() n * f(n - 1)), ...
else_(@() 1));
feval(Y(fct), 99)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment