[erlang-questions] dialyzer error: apply_op_not_a_variable

Richard Carlsson carlsson.richard@REDACTED
Thu Oct 13 18:54:59 CEST 2011


On 10/13/2011 06:36 PM, Joel Reymont wrote:
>
> On Oct 13, 2011, at 5:33 PM, Richard Carlsson wrote:
>
>> On 10/13/2011 03:52 PM, Joel Reymont wrote:
>>> This is the problem
>>>
>>> 	({?MODULE, State})(Event, Bot)
>>
>> If your snippet above is literally what's in your code, then you're doing something even stranger: having a module create an instance of itself (the tuple) and then call a function on that instance. Don't abuse the current underlying mechanism - if you want to use parameterized modules, then declare them as such:
>
>
> All I'm doing is ?MODULE:State(Event, Bot)

Ugh, sorry for the noise, I misread. Yes, you're using an "old-style 
fun", not a parameterized module. (They have the same kind of 
representation).

If the format of your function call is indeed ?MODULE:State(Event, Bot) 
then there should be no problem (assuming State is an atom).

If you need to pass around the {?MODULE, State} as in your first 
example, then use Fun=erlang:make_fun(ModuleName, FunctionName, 2). This 
lets you call Fun(Event, Bot) at the place that gets Fun.

(It would be nice if you could just say Fun=fun M:F/A, where M, F, and A 
are variables, but the language doesn't support that yet, so you can 
only use that syntax if M, F, and A are constant literals.)

     /Richard



More information about the erlang-questions mailing list