diff options
-rw-r--r-- | erlang/.gitignore | 1 | ||||
-rw-r--r-- | erlang/basic.erl | 4 | ||||
-rw-r--r-- | erlang/count.erl | 5 | ||||
-rw-r--r-- | erlang/factorial.erl | 9 | ||||
-rw-r--r-- | erlang/match.erl | 5 | ||||
-rw-r--r-- | erlang/matching_function.erl | 6 | ||||
-rw-r--r-- | erlang/words.erl | 6 |
7 files changed, 36 insertions, 0 deletions
diff --git a/erlang/.gitignore b/erlang/.gitignore new file mode 100644 index 0000000..17278c0 --- /dev/null +++ b/erlang/.gitignore @@ -0,0 +1 @@ +*.beam diff --git a/erlang/basic.erl b/erlang/basic.erl new file mode 100644 index 0000000..c7095ed --- /dev/null +++ b/erlang/basic.erl @@ -0,0 +1,4 @@ +-module(basic). +-export([mirror/1]). + +mirror(Anything) -> Anything. diff --git a/erlang/count.erl b/erlang/count.erl new file mode 100644 index 0000000..72cb378 --- /dev/null +++ b/erlang/count.erl @@ -0,0 +1,5 @@ +-module(count). +-export([count/1]). + +count(10) -> io:fwrite("10~n"); +count(N) -> io:fwrite("~b~n", [N]), count(N+1). diff --git a/erlang/factorial.erl b/erlang/factorial.erl new file mode 100644 index 0000000..f423c7c --- /dev/null +++ b/erlang/factorial.erl @@ -0,0 +1,9 @@ +-module(factorial). +-export([fact/1, fib/1]). + +fact(0) -> 1; +fact(N) -> N * fact(N-1). + +fib(0) -> 1; +fib(1) -> 1; +fib(N) -> fib(N-1) + fib(N-1). diff --git a/erlang/match.erl b/erlang/match.erl new file mode 100644 index 0000000..016cbbc --- /dev/null +++ b/erlang/match.erl @@ -0,0 +1,5 @@ +-module(match). +-export([match/1]). + +match(success) -> io:fwrite("success~n"); +match({error, Message}) -> io:fwrite("error: ~s~n", [Message]). diff --git a/erlang/matching_function.erl b/erlang/matching_function.erl new file mode 100644 index 0000000..178f189 --- /dev/null +++ b/erlang/matching_function.erl @@ -0,0 +1,6 @@ +-module(matching_function). +-export([number/1]). + +number(one) -> 1; +number(two) -> 2; +number(three) -> 3. diff --git a/erlang/words.erl b/erlang/words.erl new file mode 100644 index 0000000..4eb0354 --- /dev/null +++ b/erlang/words.erl @@ -0,0 +1,6 @@ +-module(words). +-export([words/1]). + +words([]) -> 1; +words([32|Tail]) -> 1 + words(Tail); +words([_|Tail]) -> words(Tail). |