Advertisement
obernardovieira

Appearing human (day 1) [SLiSW]

Aug 21st, 2015
455
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Erlang 0.60 KB | None | 0 0
  1. %I think, after Prolog, it becomes really easy
  2.  
  3. %exercise one (the size of the string)
  4.  
  5. -module(size_of_str).
  6. -export([the_size/1]).
  7.  
  8. the_size([_]) -> 1;
  9. the_size([_|Tail]) -> 1 + the_size(Tail).
  10.  
  11. %exercise two (count until ten)
  12.  
  13. -module(count_to).
  14. -export([to_ten/0, count_to_ten/1]).
  15.  
  16.  
  17. count_to_ten(1) -> io:format("~p~n", [1]);
  18. count_to_ten(N) -> count_to_ten(N-1), io:format("~p~n", [N]).
  19.  
  20.  
  21. to_ten() -> count_to_ten(10).
  22.  
  23. %exercise three (success and error message)
  24.  
  25. -module(error_or_success).
  26. -export([print/1]).
  27.  
  28. print(success) -> "success";
  29. print({error, Msg}) -> "error: " ++ Msg.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement