[erlang-questions] Use of unsafe variables...

Antoine Koener antoine.koener@REDACTED
Sat Nov 26 14:06:47 CET 2011


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}



More information about the erlang-questions mailing list