This in parametrized module

Magnus Henoch <>
Mon Feb 1 13:53:53 CET 2010

Dmitry Belayev <> writes:

> Hi, I have parametrized module(mymodule, [Param1, ..., ParamN]).
> I want to send this module with parameters somewhere where it's
> function will be called like this ThatModule:do_smth().
> How can I get _this_ module with all parameters? I don't like to
> create new values like tuple by hands or use mymodule:new(Param1, ...,
> ParamN).

There is a magic variable called THIS:


See section 4 of .

> And another question. Can I write my own new method?

Yes, see slide 5 of
(which shows inheritance at the same time).  Basically, write something

-module(mymodule, [A, B]).


new(X, Y, Z) ->
  instance(X, Y+Z).

I.e., export a 'new' function with any arity, which calls the 'instance'
function with the actual arity of your module.

Magnus Henoch, 
Erlang Solutions



Since January 1st 2010 Erlang Training and Consulting Ltd. has become ERLANG SOLUTIONS LTD.

More information about the erlang-questions mailing list