[erlang-questions] variable unsafe just in macros

litao cheng litaocheng@REDACTED
Sun Aug 10 08:09:58 CEST 2008


in my computer, the two DEBUG  macro all work corretly. my erlang otp is
R12B-3.

2008/8/10 Lasaro <lasaro@REDACTED>

> Sorry, I sent the message before it was ready (twice!). The question
> was
> why does this definition gives me a "variable 'Param' unsafe in
> 'case'".
>
> -define(debug,true).
>
> -ifdef(debug).
> -define(DEBUG(Msg),
> case Msg of
>          [] ->
>              io:format("{~p@~p:~p}", [?MODULE,?LINE,self()]);
>          [[_|_]=Format, [_|_]=Param] ->
>              io:format(lists:append(["{~p@~p:~p} ",Format]), [?MODULE,?
> LINE,self()|Param]);
>          [_|_] ->
>              io:format("{~p@~p:~p} "++Msg, [?MODULE,?LINE,self()]);
>          _ ->
>              io:format("{~p@~p:~p} wrong debug call", [?MODULE,?
> LINE,self()])
>      end).
> -else.
> -define(DEBUG(_M), true).
> -endif.
>
> but this one does not?
>
> -define(debug,true).
>
> -ifdef(debug).
> deb(Msg)->
>      case Msg of
>          [] ->
>              io:format("{~p@~p:~p}", [?MODULE,?LINE,self()]);
>          [[_|_]=Format, [_|_]=Param] ->
>              io:format(lists:append(["{~p@~p:~p} ",Format]), [?MODULE,?
> LINE,self()|Param]);
>          [_|_] ->
>              io:format("{~p@~p:~p} "++Msg, [?MODULE,?LINE,self()]);
>          _ ->
>              io:format("{~p@~p:~p} wrong debug call", [?MODULE,?
> LINE,self()])
>      end.
>
> -define(DEBUG(Msg), deb(Msg)).
> -else.
> -define(DEBUG(_M), true).
> -endif.
>
> Cheers.
> Lásaro
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080810/e85c683a/attachment.htm>


More information about the erlang-questions mailing list