Skip to content

Instantly share code, notes, and snippets.

@hgarcia
Created April 17, 2012 03:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hgarcia/2403205 to your computer and use it in GitHub Desktop.
Save hgarcia/2403205 to your computer and use it in GitHub Desktop.
Lerning Erlang 6
nevercalled() ->
called.
infinite([]) ->
ended;
infinite([X|T]) ->
infinite([X|T]),
nevercalled().
1> c(recursion).
{ok,recursion}
2> recursion:calculateFees(10, [5,6,7,8,9,2]).
{10,370}
3> recursion:calculateFees(10, [0.5,0.6,0.7,0.8,0.9,0.2]).
{10,37.0}
2> recursion:noguard([1,2,3]).
** exception error: no function clause matching recursion:noguard([])
infinite([]) ->
ended;
infinite([X|T]) ->
infinite([X|T]).
noguard([X|T]) ->
noguard(T).
-module(recursion).
-export([calculateFees/2]).
calculateFees(Amount, Taxes) ->
calculateFees(Amount, Taxes, 0).
calculateFees(Amount, [], Accum) ->
{Amount, Accum};
calculateFees(Amount, [X|T], Accum) ->
calculateFees(Amount, T, ((Amount * X) + Accum)).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment