[erlang-questions] Re: This in parametrized module

Dmitry Belayev rumata-estor@REDACTED
Mon Feb 1 14:41:44 CET 2010


Wow. I see "inheritance" in erlang for the first time. Is it implemented 
already?

Magnus Henoch wrote:
> 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.
>
>   



More information about the erlang-questions mailing list