【发布时间】:2019-11-25 23:50:04
【问题描述】:
我试图理解为什么我在 Erlang 中的守卫中出现此错误:
> d:/Intro/hello.erl:17: syntax error before: 'when'
> d:/Intro/hello.erl:13: function dispatch/1 undefined
> d:/Intro/hello.erl:2: Warning: export_all flag enabled - all functions
> will be exported error
代码
-module(hello).
-compile([export_all,debug_info]).
-export([pany/1]).
isList([])->true;
isList([_|_])->true;
isList(_)->false.
pany(X)->
IsList=isList(X),
Result=if IsList == true -> "Its a list";
IsList == false -> dispatch(X)
end,
Result.
dispatch(T)-> when T>3 ->
Val=if T > 4 -> 55 ;
T >5 -> 66 ;
end,
if (Val+1)==67 -> "lalalal" end;
dispatch(_)->"no result".
为什么说dispatch 是未定义的?我不想导出它,它只在模块内部使用。
在 if 中使用复杂表达式的结果也有问题吗?我知道你不允许在警卫中使用用户定义的表达式,但我想表达式的结果是好的。
【问题讨论】: