[erlang-questions] Use of unsafe variables...
Bengt Kleberg
bengt.kleberg@REDACTED
Mon Nov 28 08:32:51 CET 2011
Greetings,
This is not an answer to your question, it is a work around.
Try to always write 'case' like this (please ignore indention):
test() ->
MISSING = case lists:keyfind(ok, 1, []) of
{ok,[_]} ->
ok;
false ->
3
end,
{ok, MISSING}.
bengt
On Sat, 2011-11-26 at 14:06 +0100, Antoine Koener wrote:
> Hi everyone,
>
> Is this correct or documented ?
> Thanks
>
> Take this module:
>
> -module(tsm_case).
> -export([test/0]).
>
> test() ->
> case lists:keyfind(ok, 1, []) of
> {ok,[_]} ->
> ok;
> false ->
> MISSING = 3
> end,
> {ok, MISSING}.
>
> Compile it:
> 31> c(tsm_case).
> ./tsm_case.erl:12: variable 'MISSING' unsafe in 'case' (line 6)
> error
>
>
> Now see the difference:
>
> -module(tsm_case).
> -export([test/0]).
>
> test() ->
> case lists:keyfind(ok, 1, []) of
> {ok,[MISSING]} ->
> ok;
> false ->
> MISSING = 3
> end,
> {ok, MISSING}.
>
> 33> c(tsm_case).
> {ok,tsm_case}
> 34> tsm_case:test().
> {ok,3}
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
More information about the erlang-questions
mailing list