Created
April 17, 2012 03:28
-
-
Save hgarcia/2403205 to your computer and use it in GitHub Desktop.
Lerning Erlang 6
This file contains 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
nevercalled() -> | |
called. | |
infinite([]) -> | |
ended; | |
infinite([X|T]) -> | |
infinite([X|T]), | |
nevercalled(). |
This file contains 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
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} |
This file contains 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
2> recursion:noguard([1,2,3]). | |
** exception error: no function clause matching recursion:noguard([]) |
This file contains 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
infinite([]) -> | |
ended; | |
infinite([X|T]) -> | |
infinite([X|T]). |
This file contains 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
noguard([X|T]) -> | |
noguard(T). |
This file contains 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(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