The {imports,Value} tuple may be removed in a future release because Value is always an empty list. Do not write code that depend on it being present.
Erlang code is divided into modules. A module consists of a sequence of attributes and function declarations, each terminated by period (.). Example:
-module(m). % module attribute -export([fact/1]). % module attribute fact(N) when N>0 -> % beginning of function declaration N * fact(N-1); % | fact(0) -> % | 1. % end of function declaration
See the Functions chapter for a description of function declarations.
A module attribute defines a certain property of a module. A module attribute consists of a tag and a value.
-Tag(Value).
Tag must be an atom, while Value must be a literal term. As a convenience in user-defined attributes, the literal term Value the syntax Name/Arity (where Name is an atom and Arity a positive integer) will be translated to {Name,Arity}.
Any module attribute can be specified. The attributes are stored in the compiled code and can be retrieved by calling Module:module_info(attributes) or by using beam_lib(3).
There are several module attributes with predefined meanings, some of which have arity two, but user-defined module attributes must have arity one.
Pre-defined module attributes should be placed before any function declaration.
It is possible to specify that the module is the callback module for a behaviour:
-behaviour(Behaviour).
The atom Behaviour gives the name of the behaviour, which can be a user defined behaviour or one of the OTP standard behaviours gen_server, gen_fsm, gen_event or supervisor.
The spelling behavior is also accepted.
Read more about behaviours and callback modules in OTP Design Principles.
The same syntax as for module attributes is used by for record definitions:
-record(Record,Fields).
Record definitions are allowed anywhere in a module, also among the function declarations. Read more in Records.
The same syntax as for module attributes is used by the preprocessor, which supports file inclusion, macros, and conditional compilation:
-include("SomeFile.hrl"). -define(Macro,Replacement).
Read more in The Preprocessor.
The same syntax as for module attributes is used for changing the pre-defined macros ?FILE and ?LINE:
-file(File, Line).
This attribute is used by tools such as Yecc to inform the compiler that the source program was generated by another tool and indicates the correspondence of source files to lines of the original user-written file from which the source program was produced.
Comments may be placed anywhere in a module except within strings and quoted atoms. The comment begins with the character "%", continues up to, but does not include the next end-of-line, and has no effect. Note that the terminating end-of-line has the effect of white space.
The compiler automatically inserts the two special, exported functions into each module: module_info/0 and Module:module_info/1. These functions can be called to retrieve information about the module.
The module_info/0 function in each module returns a list of {Key,Value} tuples with information about the module. Currently, the list contain tuples with the following Keys: attributes, compile, exports, and imports. The order and number of tuples may change without prior notice.
The {imports,Value} tuple may be removed in a future release because Value is always an empty list. Do not write code that depend on it being present.
The call module_info(Key), where key is an atom, returns a single piece of information about the module.
The following values are allowed for Key: