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

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


Doh!

Lennart, thank you, that's the kind of solution I was expecting, but  
didn't think of !-)
So it's now:
-define(IOFUN(), io:format("~s: ", [begin {_,{_,F,_}} = process_info 
(self(),current_function), F end])).

Tim, I hadn't thought of your suggestion, so thank you for pointing  
it out:
-define(IOFUN(), io:format("~s: ", [element(2, element(2, process_info 
(self(),current_function)))])).
Is it in some way 'better' to avoid the pattern match, or is it  
simply personal preference?

I didn't ask my question well. I'd realised the variable F was  
getting pushed into a higher scope, but I had thought that 'case ...  
end' established a new scope, so I didn't/don't understand why F was  
exported, or what to do about it.

I had tried:
-define(IOFUN(), io:format("~s: ",
     [begin case process_info(self(),current_function) of {_,{_,F,_}}  
->F end end])).
thinking the 'begin ... end' would kill the scope issue, but that  
didn't stop the warning, and F was still exported to the substitution  
site!

test1() ->
     ?IOFUN(), io:format("see if F is bound~n"),
     F = wibble.
fails with a ...  {{badmatch,wibble}, error.

Can anyone explain why/how  "case ... of ... -> F end"  and  "begin  
case ... of ... -> F end end"  export F, yet
"[begin {_,{_,F,_}} = process_info(self(),current_function), F end]"
does not?
I'd expect all three to simply return the *value* of F as the value  
of the case ... end/begin ... end expressions.

Garry

> Hi, the easiest way would be to refrain from using a case when you  
> don't have
> more than one branch.
>
> Try
>
> [begin  {_,{_,F,_}}=process_info(self(),current_function), F end]
>
> Another reason not to use your suggestion is that define leads to  
> that the
> subtituation gets copied into the locations where you use ?IOFUN.  
> And since F
> actually gets exported (since it becomes bound in all (the only)  
> branches)
> it might very well mess with another varible F in the variable  
> scoop where
> you use IOFUN. What I am trying to say in too many words is that  
> there is
> a very good reason for the warning to be there :-)
>
> Best Regards
> Lennart
>
>
> ---------------------------------------------------------------------- 
> ---------
> Lennart Öhman                    phone: +46 8 587 623 27
> Sjöland & Thyselius Telecom AB   cell : +46 70 552 6735
> Hälsingegatan 43, 10th floor     fax  : +46 8 667 8230
> SE-113 31 STOCKHOLM, SWEDEN      email: lennart.ohman@REDACTED
> -----Original Message-----
> From: erlang-questions-bounces@REDACTED [mailto:erlang-questions- 
> bounces@REDACTED] On Behalf Of G Bulmer
> Sent: den 22 september 2007 16:18
> To: erlang-questions@REDACTED
> Subject: [erlang-questions] Help - Can I stop this warning?
>
> 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?
>
> Garry
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions

Garry Bulmer

email: gbulmer@REDACTED
Home: +44 (0)24 7667 9497
Mobile: +44 (0)7726 880058






More information about the erlang-questions mailing list