Created
July 21, 2011 19:54
-
-
Save amtal/1098051 to your computer and use it in GitHub Desktop.
Local recursion with access to lexical scope.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(iter). | |
-export([fac/1]). | |
-define( for(Arg,Seed,Body) | |
, begin F = fun(Iter,Arg)->Body end, F(F,Seed) end | |
). | |
-define( iter(Arg) | |
, Iter(Iter,Arg) | |
). | |
fac(N)-> | |
?for({I,Y}, {N,1}, | |
case (I>1) of | |
true -> ?iter({I-1,Y*I}); | |
false -> Y | |
end). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment