【发布时间】:2012-04-29 23:58:19
【问题描述】:
是这样的:
% 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 的新手。是否有一些约定来处理这个问题?
谢谢!
【问题讨论】:
标签: erlang