multiple case ... of ...

Richard Carlsson richardc@REDACTED
Tue Aug 10 14:23:54 CEST 2004


On Tue, 10 Aug 2004, Dietmar Schäfer wrote:

> Hi !
>
> Is there anybody out ther who can tell me how to do things
> like this:

You just need another name for the second Reason (e.g. Reason1).
Variables bound in the first case-expression are exported, and
can be used later - but only if they are bound in all the clauses,
otherwise they are "unsafe", which is a compile time error.

So the Reason in the second case-expression wants to use the above
binding since it is not a new variable. But the existing binding
is unsafe.

Either put the two cases in different functions, so they are not
in the same scope, or rename the second Reason.

	/Richard


> create_table() ->
>        case mnesia:create_table(fourd_mib_variables, [{snmp, [{key,
> string}]},  %%  o.k. ??
>                  {attributes, record_info(fields, fourd_mib_variables)},
>                  {disc_copies, [nodes()]}]) of
>          {atomic, ok}     -> io:format("table fourd_mib_variables could
> be created"),
>                              ok;
>          {aborted,Reason} -> io:format("creation of database failed
> reason.~n ~w",[Reason]),
>                              Reason
>        end,
>
>
>        case mnesia:create_table(command_table, [{snmp, [{key,
> string}]},  %% ist das so o.k. ??
>                  {attributes, record_info(fields, command_table)},
>                  {disc_copies, [nodes()]}]) of
>          {atomic, ok}     -> io:format("table command_table could be
> created"),
>                              ok;
>          {aborted,Reason} -> io:format("creation of database
> command_table failed reason.~n ~w",[Reason]),
>                              Reason
>        end.
>
>
>
> the compiler tells me :
>
> src/cmmc_foc.erl:38: variable 'Reason' unsafe in 'case' (line 24)
> error
>
>
> Best Regards !
>
>
> Dietmar
>
>
>

Richard Carlsson (richardc@REDACTED)   (This space intentionally left blank.)
E-mail: Richard.Carlsson@REDACTED	WWW: http://user.it.uu.se/~richardc/
 "Having users is like optimization: the wise course is to delay it."
   -- Paul Graham



More information about the erlang-questions mailing list