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
2010-06-15 16:58:53
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
2010-06-15 21:58:30
Yes, that worked, thanks
Zubair
2010-06-16 09:05:11
+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
2010-06-15 22:05:25