[erlang-questions] Parameterized module idioms
Vlad Dumitrescu
vladdu55@REDACTED
Fri Apr 23 08:28:20 CEST 2010
Hi,
2010/4/23 Richard O'Keefe <ok@REDACTED>:
> A module with parameters is basically a surpassingly strange
> way to write a function that returns a record of functions.
>
> Right now, we can do exactly that:
>
> new(V1, ..., Vk) ->
> #record{
> f1 = fun (...) -> ... end,
> ...
> fm = fun (...) -> ... end
> }.
>
> This thing, which I regard as an aggregate of closures,
> can be passed around (just as an instance of a module with
> parameters can), and the functions can be invoked:
>
> R#record.fi(...)
Cool!
This record is then a representation of an anonymous module instance.
Taken a step longer and adding some "normal" data fields, it becomes
an object of the OO-kind, with the funs building the virtual method
table. A classless object, JavaScript-like, and immutable. Then we can
relate this to the discussion recently brought to our attention by
Robert Virding in the thread named "Clojure and OO, and Erlang"...
best regards,
Vlad
More information about the erlang-questions
mailing list