情况就是这样:
% 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).
Run Code Online (Sandbox Code Playgroud)
如果用户输入非整数,则会发生以下情况:
11> effects:print('alfalfa').
** exception error: no function clause matching effects:print(alfalfa)
Run Code Online (Sandbox Code Playgroud)
关于哲学:我应该以这种方式纠正我的程序,以便"捕获所有"的输入?
% 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.
Run Code Online (Sandbox Code Playgroud)
我是二郎的新手.是否有一些处理这个问题的惯例?
谢谢!
| 归档时间: |
|
| 查看次数: |
149 次 |
| 最近记录: |