Skip to content

Instantly share code, notes, and snippets.

@oskimura
Created August 18, 2011 10:02
Show Gist options
  • Select an option

  • Save oskimura/1153775 to your computer and use it in GitHub Desktop.

Select an option

Save oskimura/1153775 to your computer and use it in GitHub Desktop.
-module (fact).
-export ([fact/1]).
print(X) ->
io:format("~p\n",[X]).
fact(0,Pid) ->
Pid ! 1;
fact(N,Pid) ->
Id = spawn(fun () ->
receive
M ->
print(M),
Pid ! (M*N)
end
end),
fact(N-1,Id).
fact(N) ->
Id = spawn(fun () ->
receive
M ->
print(M)
end
end),
fact(N,Id).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment