Skip to content

Instantly share code, notes, and snippets.

@imetallica
Last active August 29, 2015 14:27
Show Gist options
  • Save imetallica/f3859378c4dcad989b55 to your computer and use it in GitHub Desktop.
Save imetallica/f3859378c4dcad989b55 to your computer and use it in GitHub Desktop.
-module(factorial).
-export[fac1/1, fac2/1].
%% With guards
fac1(x) when x <= 0 -> 1;
fac1(x) when x > 0 -> x * fac(x-1).
%% With pattern-matching [does not handle x < 0]
fac2(x) ->
case x of
0 -> 1;
_ -> x * fac(x-1).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment