Created
November 17, 2011 21:28
-
-
Save japaz/1374590 to your computer and use it in GitHub Desktop.
7L7W Erlang - Day 1
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(day1). | |
-export([number_of_words/1]). | |
-export([count/1]). | |
-export([print_message/1]). | |
% Write a function that uses recursion to return the number of | |
% words in a string. | |
list_size([]) -> 0; | |
list_size([H|T]) -> 1+list_size(T). | |
number_of_words(Cadena) -> list_size(string:tokens(Cadena, " ,.")). | |
% Write a function that uses recursion to count to ten | |
count(0) -> io:format("Count: ~w~n",[0]); | |
count(N) when N > 0 -> io:format("Count: ~w~n",[N]), count(N-1). | |
% Write a function that uses matching to selectively print success | |
% or error: message given input of the form {error, Message} or success. | |
print_message({error, Message}) -> io:format("Error: ~s~n", [Message]); | |
print_message(success) -> io:format("Success~n"). |
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
% The Erlang language’s official site | |
% http://www.erlang.org/ | |
% http://www.erlang.se/ | |
% Official documentation for Erlang’s function library | |
% http://www.erlang.org/doc/ | |
% The documentation for Erlang’s OTP library | |
% http://www.erlang.org/doc/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment