This in parametrized module

Magnus Henoch magnus@REDACTED
Mon Feb 1 13:53:53 CET 2010


Dmitry Belayev <rumata-estor@REDACTED> 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:

other_module:call_me(THIS).

See section 4 of
http://www.erlang.se/workshop/2003/paper/p29-carlsson.pdf .

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

Yes, see slide 5 of http://www.erlang.se/euc/07/papers/1700Carlsson.pdf
(which shows inheritance at the same time).  Basically, write something
like:

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

-export([new/3]).

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, magnus@REDACTED
Erlang Solutions
http://www.erlang-solutions.com/
---------------------------------------------------

---------------------------------------------------

WE'VE CHANGED NAMES!

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

www.erlang-solutions.com



More information about the erlang-questions mailing list