Erlang: module attribute

点点圈 提交于 2019-12-05 22:58:46

问题


I am new to Erlang. Found the following -module attribute declaration in an existing Erlang project:

-module(mod_name, [Name, Path, Version]).

What does mean the second parameter (list [Name, Path, Version]) here?

I haven't found any information in the Erlang reference on it.


回答1:


This defines a parameterised erlang module - one you can "instantiate" with new and then access the parameters passed by that new when executing code in your module.

A very brief overview is here:

http://myotherpants.com/2009/04/parameterized-modules-in-erlang/




回答2:


This is a parametrized module. Here is the original paper on it. Basically you can create instances of the module binding specific values to those variables. You can initialize one as:

> Mod = mod_name:new("MyName", "/path", '0.1').

and then call its functions as:

> Mod:function(...)

where the module parameters are also available in the function body.



来源:https://stackoverflow.com/questions/1358230/erlang-module-attribute

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!