Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -module(day1).
- -export([count_words/1,count_to_N/1,messenger/1]).
- % I don't know how to count words in a string recursively
- % so I'll do it like I usually do it by splitting up the string
- % using spaces as a boundary and computing the length of the resulting
- % list
- count_words(S) -> L = re:split(S," +"), length(L).
- % recursive up counting with anonymous recursive functions. this is really weird.
- % I should look into the whole Y combinator business.
- count_to_N(N) ->
- Counter =
- fun(F,X) when X > N ->
- io:format("done~n",[]);
- (F,X) ->
- io:format("~w~n",[X]),F(F,X+1) end,
- Counter(Counter,1).
- % pattern matching messenger
- messenger({error,Message}) -> io:format("error: ~w~n",[Message]);
- messenger(_) -> io:format("success~n",[]).
Add Comment
Please, Sign In to add comment