[erlang-questions] Help - Can I stop this warning?
Richard Carlsson
richardc@REDACTED
Sat Sep 22 18:28:01 CEST 2007
Tim Bates wrote:
> G Bulmer wrote:
>> I have been playing with this macro to print the current functions name:
>>
>> -define(IOFUN(), io:format("~s: ", [case process_info(self
>> (),current_function) of {_,{_,F,_}} ->F end])).
>>
>> Unfortunately, I get this irritating warning on *every* function, on
>> the first use of ?IOFUN():
>> ./script.erl:34: Warning: variable 'F' exported from 'case' (line 31)
>> ...
>>
>> Can someone suggest how I get rid of it?
>
> -define(IOFUN(), io:format("~s: ", [element(2, element(2,
> process_info(self(),current_function)))])).
That's a good solution in this case, but for the general case when you
want a macro to do something more complicated, and avoid contaminating
the environment, use a fun-expression to simulate local variables:
-define(my_macro, ((fun()-> ... end)())).
Variables defined in ... are not exported outside the fun.
/Richard
More information about the erlang-questions
mailing list