[erlang-questions] Re: This in parametrized module
Fred Hebert
mononcqc@REDACTED
Mon Feb 1 14:47:51 CET 2010
Yes, see -extend(ModuleName).
This will make it so any functions called of the form
"YourModule:Function()" that are not part of your current module will be
looked up into the extended module.
This is not supported, as far as I know.
On Mon, Feb 1, 2010 at 8:41 AM, Dmitry Belayev <rumata-estor@REDACTED> wrote:
> 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.
>>
>>
>>
>
>
> ________________________________________________________________
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org
>
>
More information about the erlang-questions
mailing list