Created
July 9, 2013 01:21
-
-
Save krazylegz/5953900 to your computer and use it in GitHub Desktop.
Dave Thomas's PragPub June 6 Elixir examples converted (back?) to 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
| -module(kiyu). | |
| -export([sum/1, fib/1]). | |
| sum([]) -> | |
| 0; | |
| sum([First | Rest]) -> | |
| First + sum(Rest). | |
| fib(0) -> | |
| 1; | |
| fib(1) -> | |
| 1; | |
| fib(N) -> | |
| fib(N-2) + fib(N-1). |
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
| $ erl | |
| Erlang R15B03 (erts-5.9.3.1) [source] [64-bit] [smp:8:8] [async-threads:0] [hipe] [kernel-poll:false] [dtrace] | |
| Eshell V5.9.3.1 (abort with ^G) | |
| 1> c(kiyu). | |
| {ok,kiyu} | |
| 2> kiyu:sum([1,5,100,99]). | |
| 205 | |
| 3> kiyu:fib(10). | |
| 89 | |
| 4> kiyu:fib(1). | |
| 1 | |
| 5> kiyu:fib(0). | |
| 1 | |
| 6> halt(). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment