[erlang-questions] Interesting style i haven't seen....

Adriano Bonat adrianob@REDACTED
Fri Oct 30 17:53:10 CET 2009


Exactly,

9> Blah = {modname, "arg1", "arg2", 3}.
{modname,"arg1","arg2",3}
10> Blah:func().
** exception error: undefined function modname:func/1


On Fri, Oct 30, 2009 at 2:45 PM, Colm Dougan <colm.dougan@REDACTED> wrote:
> I think it works because
>
> Dog:woof()
>
> means the same thing as :
>
> dog:woof(Dog)
>
> .. by virtue of the fact that Dog is a tuple with a first element of
> "dog".  I seem to recall this is a consequence of the parametrized
> modules feature.
>
> Colm
>
> On Fri, Oct 30, 2009 at 4:25 PM, Greg Smyth <gsmyth@REDACTED> wrote:
>> A friend just came up with this, and i thought it was pretty
>> interesting(arguments against doing this kind of thing in Erlang
>> aside...) as I'd never seen this type of thing done before...
>>
>> Anyone care to shed some light on why/how this works:-
>>
>> %%
>> -module(dog).
>> -export([new/1, woof/1]).
>>
>> new(Name) -> {dog, Name}.
>>
>> woof(Self) ->
>>  {dog, Name} = Self,
>>  io:format("~p says 'woof!'~n", [Name]).
>> %%
>>
>> % 13> c(dog).
>> % {ok,dog}
>>
>> % 14> Dog = dog:new("Fido").
>> % {dog,"Fido"}
>>
>> % 15> Dog:woof().
>> % "Fido" says 'woof!'
>> % ok
>>
>> Many thanks,
>> Greg
>>
>> ________________________________________________________________
>> erlang-questions mailing list. See http://www.erlang.org/faq.html
>> erlang-questions (at) erlang.org
>>
>>
>
> ________________________________________________________________
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org
>
>


More information about the erlang-questions mailing list