Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Erlang: module attribute

Tags:

module

erlang

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.

like image 200
alexey Avatar asked Aug 31 '09 16:08

alexey


People also ask

What does Module do in Erlang?

Erlang code is divided into modules. A module consists of a sequence of attributes and function declarations, each terminated by period (.). For a description of function declarations, see Function Declaration Syntax.

What are module attributes in python?

A module is a Python object with arbitrarily named attributes that you can bind and reference. Simply, a module is a file consisting of Python code. A module can define functions, classes and variables. A module can also include runnable code.

What does Erlang compile to?

Erlang programs must be compiled to object code. The compiler can generate a new file that contains the object code. The current abstract machine, which runs the object code, is called BEAM, therefore the object files get the suffix .


2 Answers

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/

like image 76
Alan Moore Avatar answered Oct 12 '22 11:10

Alan Moore


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.

like image 8
Zed Avatar answered Oct 12 '22 11:10

Zed