[erlang-questions] an erlang "gotcha"
Thu Apr 5 13:18:16 CEST 2007
In your example 'and' is evaluated before '/=', so it tries to do
'is_pid(Pid) and L' first which fails since L is not boolean. It seems
to go against normal intuition, that changing 'and' to 'andalso' makes
it do '/=' before 'andalso'. Anyhow this is explained by the Operator
Anthony Shipman skrev:
> Is there a place where difficulties with erlang and their solutions are
> described? Perhaps another page at Trapexit.
> Here's one that got me.
> run() ->
> Pid = spawn(fun() -> io:fwrite("spawned~n") end),
> L = [1, 2, 3],
> io:fwrite("Pid=~p L=~p~n", [Pid, L]),
> is_pid(Pid) and L /=  ->
> io:fwrite("it worked~n");
> true ->
> io:fwrite("it failed~n")
> It prints out "it failed". If you change the 'and' to 'andalso' it works.
More information about the erlang-questions