Quantcast

module syntax help

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

module syntax help

人间世
code get from openpoker:“-module(exch, [Cbk, Context, Modules]).”
What’s it mean?Is it correct module syntax?thank!

_______________________________________________
erlang-questions mailing list
[hidden email]
http://www.erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: module syntax help

shiwei xu
See http://erlang-china.org/study/parameterized-module.html

2009/4/13 人间世 <[hidden email]>
code get from openpoker:“-module(exch, [Cbk, Context, Modules]).”
What’s it mean?Is it correct module syntax?thank!

_______________________________________________
erlang-questions mailing list
[hidden email]
http://www.erlang.org/mailman/listinfo/erlang-questions


_______________________________________________
erlang-questions mailing list
[hidden email]
http://www.erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: module syntax help

KDr2-2
In reply to this post by 人间世
It's parameterized module,To declare a parameterized module, simply specify some variable names in the module declaration:

-module(foo,[Bar, Baz]).

That's it! You're done. You've created a parameterized module. You got a func called 'new' , And you can now use Bar and Baz in the scope of any functions defined in your module.

code:
-module(xx,[A,B]).
-compile(export_all).

test()->
    io:format("A=~w,B=~w~n",[A,B]).


result:

Eshell V5.6.5  (abort with ^G)
1> B=xx:new(abc,"hehe").
{xx,abc,"hehe"}
2> B:test().
A=abc,B=[104,101,104,101]
ok
3>

btw: 中文名?中国人?

2009/4/13 人间世 <[hidden email]>
code get from openpoker:“-module(exch, [Cbk, Context, Modules]).”
What’s it mean?Is it correct module syntax?thank!

_______________________________________________
erlang-questions mailing list
[hidden email]
http://www.erlang.org/mailman/listinfo/erlang-questions



--
Best Regards,
   -- KDr2, at x-macro.com.

_______________________________________________
erlang-questions mailing list
[hidden email]
http://www.erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: module syntax help

Lev Walkin
In reply to this post by 人间世

Easy one:

http://www.google.com/search?q=parameterized+modules+erlang

人间世 wrote:

> code get from openpoker:“-module(exch, [Cbk, Context, Modules]).”
> What’s it mean?Is it correct module syntax?thank!
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> erlang-questions mailing list
> [hidden email]
> http://www.erlang.org/mailman/listinfo/erlang-questions

_______________________________________________
erlang-questions mailing list
[hidden email]
http://www.erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: module syntax help

Steve Davis
Followup question:

If you call new twice, e.g.

1> P = mymodule:new(Params).
2> P = mymodule:new(Params).

I'd be right in thinking that P is exactly the same instance of the
parameterized module, correct?

i.e. if I call mymodule:new(Params) with the same parameters 100000
times there's no memory (or otherwise) impact on the VM?

/s




On Apr 13, 4:09 am, Lev Walkin <[hidden email]> wrote:

> Easy one:
>
> http://www.google.com/search?q=parameterized+modules+erlang
>
> 人间世 wrote:
> > code get from openpoker:"-module(exch, [Cbk, Context, Modules])."
> > What's it mean?Is it correct module syntax?thank!
>
> > ------------------------------------------------------------------------
>
> > _______________________________________________
> > erlang-questions mailing list
> > [hidden email]
> >http://www.erlang.org/mailman/listinfo/erlang-questions
>
> _______________________________________________
> erlang-questions mailing list
> [hidden email]://www.erlang.org/mailman/listinfo/erlang-questions
_______________________________________________
erlang-questions mailing list
[hidden email]
http://www.erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: module syntax help

Richard Carlsson-2
Steve Davis wrote:

> If you call new twice, e.g.
>
> 1> P = mymodule:new(Params).
> 2> P = mymodule:new(Params).
>
> I'd be right in thinking that P is exactly the same instance of the
> parameterized module, correct?
>
> i.e. if I call mymodule:new(Params) with the same parameters 100000
> times there's no memory (or otherwise) impact on the VM?

The impact would be similar to running the following function
the same number of times:

   new(P1,...,Pn) ->  {some_tag, P1, ..., Pn}..

I.e., a small object is created on the heap, on the order of n+k
words for some small k. As usual, these will be garbage collected
when they are no longer referenced. (The current representation
uses tuples, but this is meant to change, so never rely on that.)

    /Richard
_______________________________________________
erlang-questions mailing list
[hidden email]
http://www.erlang.org/mailman/listinfo/erlang-questions
Loading...