Interesting style i haven't seen....

Greg Smyth gsmyth@REDACTED
Fri Oct 30 17:25:55 CET 2009

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:-

-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,

More information about the erlang-questions mailing list