Skip to content

Instantly share code, notes, and snippets.

@myw 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
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.