Skip to content

Commit

Permalink
add chapter 3
Browse files Browse the repository at this point in the history
  • Loading branch information
HpyHacking committed Jun 27, 2011
1 parent 814618f commit 5a187ec
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions chapter_3/def.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
-module(def).
-export([convert/1, convert_def/1]).

convert(Day) ->
case Day of
monday -> 1;
tuesday -> 2;
wednesday -> 3;
thursday -> 4;
friday -> 5;
staturday -> 6;
sunday -> 7
end.

% 8> def:convert(amonday).
% ** exception error: no case clause matching amonday
% in function def:convert/1

convert_def(Day) ->
case Day of
monday -> 1;
tuesday -> 2;
wednesday -> 3;
thursday -> 4;
friday -> 5;
staturday -> 6;
sunday -> 7;
Other -> {error, unknown_day}
end.

% 2> c(def).
% ./def.erl:13: Warning: variable 'Other' is unused
% {ok,def}
% 3> def:convert(sunday).
% 7
% 4> def:convert(other).
% {error,unknown_day}

0 comments on commit 5a187ec

Please sign in to comment.