这种情况:erlang phylosophy:我应该让用户处理错误的输入吗?
% print/1: Prints out the integers between 1 and N
print(0) -> io:format("~w~n", [0]);
print(N) when is_integer(N) ->
io:format("~w~n", [N]),
print(N - 1).
如果用户输入一个非整数,出现这种情况:
11> effects:print('alfalfa').
** exception error: no function clause matching effects:print(alfalfa)
是关于哲学史:我应该纠正我的程序这样,为了“追赶所有'种类的输入?
% print/1: Prints out the integers between 1 and N
print(0) -> io:format("~w~n", [0]);
print(N) when is_integer(N) ->
io:format("~w~n", [N]),
print(N - 1).
% Last Line added:
print(_Other) -> false.
我是新的erlang。有处理这个问题的一些约定吗?
谢谢!
非常感谢! –