Last active
August 29, 2015 14:25
-
-
Save solidnerd/26432de3e0171c5ad5f6 to your computer and use it in GitHub Desktop.
Lets go shopping in Erlang
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
% shop.erl | |
-module(shop). | |
-export([cost/1]). | |
cost(oranges) -> 5; | |
cost(newspaper) -> 8; | |
cost(apples) -> 2; | |
cost(pears) -> 9; | |
cost(milk) -> 7. | |
% shop1.erl | |
-module(shop1). | |
-export([total/1]). | |
total([ {What,N} | T]) -> shop:cost(What)*N + total(T); | |
total([]) -> 0. | |
% See the result for | |
shop1:total([{oranges,5},{milk,3}] . | |
% First 5 * 5 + total([{milk,3}] | |
% Second 25 + 21 + total([]) | |
% Third 25 + 21 + 0 | |
% Result 46 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment