tags:

views:

62

answers:

2

I have a paramterised module in Erlang in which I wish to call a function A from within function B of the same parameterised module. How can I do this?

+5  A: 

From this paper:

in every function of an abstract module, the variable THIS is always implicitly bound to the current module instance

So you can simply write inside a function B:

THIS:A().
xap4o
You don't have to do this when calling functions within the same module, the THIS is automatically handle. It is actually added to the arguments. Calling `THIS:b()` can only be used for exported functions and will then become a normal erlang "remote" call. The examples are very short but look in Fig 3.
rvirding
Yes, that worked, thanks
Zubair
+2  A: 

Just to recapitulate in an answer. You don't have to do anything special to call functions within a parametrised module, just write the code as you normally would. It is only when want to make an "remote" call to an exported function from within the module you need THIS:a(). Externally you need the parametrised module reference.

Though I agree with @Christian, stay away from them, you don't really need them.

rvirding