Created
March 4, 2012 08:42
-
-
Save devnoo/1971407 to your computer and use it in GitHub Desktop.
seven languages in seven weeks, erlang day 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
-module(counter). | |
-export([count_to_ten/0]). | |
count_to_ten() -> count_to_ten(1). | |
count_to_ten(10) -> io:fwrite("10" ,[]); | |
count_to_ten(N) -> io:fwrite("~w~n", [N]), count_to_ten(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
-module(logger). | |
-export([log/1]). | |
log({error, Message}) -> io:format("error:" ++ Message); | |
log(success) -> io:format("success"). |
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(word_counter). | |
-export([word_count/1]). | |
%empty string | |
word_count([]) -> 0; | |
%ignoring starting space | |
word_count([32|Rest]) -> word_count(Rest); | |
%last_character so count as word | |
word_count([_|[]]) -> 1; | |
%last character before space so count | |
word_count([_|[32|Rest]]) -> 1 + word_count(Rest); | |
%in the middle of a word, so don't count | |
word_count([_|Rest]) -> word_count(Rest). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment