[erlang-questions] Help - Can I stop this warning?

G Bulmer gbulmer@REDACTED
Sat Sep 22 18:44:50 CEST 2007


So "begin ... end" does *not* introduce a new lexical scope. It  
*only* groups expressions.
Ah! I think I've got it. Tripped up by my own baggage.

Thank you,

> 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