[erlang-questions] Parameterized module initialization
Joe Armstrong
erlang@REDACTED
Tue Jun 26 14:53:18 CEST 2012
There is an undocumented way of doing this (which one day will become standard)
Suppose we define X as follows:
> X = {mod1, a,b,c}.
{mod1, a,b,c}.
X is now an instance of a parameterised module. if we now call the
function X:func1(x,y) then what actually gets called is the function
mod1:func1(x,y,{mod1,a,b,c})
So for example if we define a module sneaky.erl like this:
-module(sneaky).
-export([test/2, hide/1]).
test(X, Y) -> {sneaky, X, Y}.
hide(Something) ->
{sneaky, Something}.
Then in the shell we can do this:
1> c(sneaky).
{ok,sneaky}
2> X = sneaky:hide({rectange,10,file,"foo"}).
{sneaky,{rectange,10,file,"foo"}}
3> X:test(abc).
{sneaky,abc,{sneaky,{rectange,10,file,"foo"}}}
Cheers
/Joe
On Tue, Jun 26, 2012 at 1:09 PM, Zhemzhitsky Sergey
<Sergey_Zhemzhitsky@REDACTED> wrote:
> Hi there,
>
>
>
> I’d like to use parameterized module to save some readonly staff and use it
> later at every function call.
>
>
>
> As I understand the compiler implicitly makes every function have parameters
> of the module, so even the function with zero arguments will be exported as
> a function with arity that corresponds to the number of module parameters.
>
>
>
> Is it possible to have a function in a parameterized module that can be
> exported without any parameters of the module?
>
>
>
> Best Regards,
>
> Sergey
>
>
>
> _______________________________________________________
>
>
>
> The information contained in this message may be privileged and conf
> idential and protected from disclosure. If you are not the original intended
> recipient, you are hereby notified that any review, retransmission,
> dissemination, or other use of, or taking of any action in reliance upon,
> this information is prohibited. If you have received this communication in
> error, please notify the sender immediately by replying to this message and
> delete it from your computer. Thank you for your cooperation. Troika Dialog,
> Russia.
>
> If you need assistance please contact our Contact Center (+7495) 258 0500 or
> go to www.troika.ru/eng/Contacts/system.wbp
>
>
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
More information about the erlang-questions
mailing list