<div class="gmail_quote">On Tue, Jun 26, 2012 at 6:53 AM, Joe Armstrong <span dir="ltr"><<a href="mailto:erlang@gmail.com" target="_blank">erlang@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
There is an undocumented way of doing this (which one day will become standard)<br>
<br>
Suppose we define X as follows:<br>
<br>
> X = {mod1, a,b,c}.<br>
{mod1, a,b,c}.<br>
<br>
X is now an instance of a parameterised module. if we now call the<br>
function X:func1(x,y) then what actually gets called is the function<br>
mod1:func1(x,y,{mod1,a,b,c})<br>
<br>
So for example if we define a module sneaky.erl like this:<br>
<br>
-module(sneaky).<br>
-export([test/2, hide/1]).<br>
<br>
test(X, Y) -> {sneaky, X, Y}.<br>
<br>
hide(Something) -><br>
{sneaky, Something}.<br>
<br>
Then in the shell we can do this:<br>
<br>
1> c(sneaky).<br>
{ok,sneaky}<br>
2> X = sneaky:hide({rectange,10,file,"foo"}).<br>
{sneaky,{rectange,10,file,"foo"}}<br>
3> X:test(abc).<br>
{sneaky,abc,{sneaky,{rectange,10,file,"foo"}}}<br>
<br>
Cheers<br></blockquote><div><br>Personally I love this form and use it my self. I like parametrized modules, but I do not use the normal decoration, I build it up myself, just like this. It is wonderfully obvious to me. Although I usually have a parent module use a helper module to handle all that, but I still do it explicitly as it is easy for me to forget about the decorations otherwise.<br>
</div></div>