From 9fe8adf35c16ab5d4566b03f3b36863c90b5b6dd Mon Sep 17 00:00:00 2001
From: Hans Bolinder Erlang code is divided into modules. A module consists
of a sequence of attributes and function declarations, each
- terminated by period (.). Example:
Example:
-module(m). % module attribute -export([fact/1]). % module attribute @@ -42,50 +43,52 @@ fact(N) when N>0 -> % beginning of function declaration N * fact(N-1); % | fact(0) -> % | 1. % end of function declaration-
See the
For a description of function declarations, see
+
A module attribute defines a certain property of a - module. A module attribute consists of a tag and a value.
+ module. +A module attribute consists of a tag and a value:
-Tag(Value).
Any module attribute can be specified. The attributes are stored
in the compiled code and can be retrieved by calling
-
There are several module attributes with predefined meanings, - some of which have arity two, but user-defined module +
Several module attributes have predefined meanings. + Some of them have arity two, but user-defined module attributes must have arity one.
Pre-defined module attributes should be placed before any +
Pre-defined module attributes is to be placed before any function declaration.
Module declaration, defining the name of the module.
- The name
This attribute should be specified first and is the only - attribute which is mandatory.
+This attribute is to be specified first and is the only + mandatory attribute.
Exported functions. Specifies which of the functions - defined within the module that are visible outside +
Exported functions. Specifies which of the functions, + defined within the module, that are visible from outside the module.
Imported functions. Imported functions can be called - the same way as local functions, that is without any module +
Imported functions. Can be called + the same way as local functions, that is, without any module prefix.
Compiler options.
Compiler options.
Module version.
If this attribute is not specified, the version defaults to the MD5 checksum of the module.
Names a function that should be run automatically when a
- module a loaded. See
This attribute names a function that is to be run
+ automatically when a
+ module is loaded. For more information, see
+
-behaviour(Behaviour).
The atom
The spelling
The callback functions of the module can be specified either
directly by the exported function
-callback Name(Arguments) -> Result.-
where
Here,
The same syntax as for module attributes is used by +
The same syntax as for module attributes is used for record definitions:
-record(Record,Fields).@@ -163,7 +176,7 @@ behaviour_info(callbacks) -> Callbacks.
The same syntax as for module attributes is used by the preprocessor, which supports file inclusion, macros, and conditional compilation:
@@ -171,7 +184,7 @@ behaviour_info(callbacks) -> Callbacks. -include("SomeFile.hrl"). -define(Macro,Replacement). -Read more in
Read more in
-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.
+This attribute is used by tools, such as Yecc, to inform the + compiler that the source program is generated by another tool. + It also indicates the correspondence of source files to lines of + the original user-written file, from which the source program + is produced.
A similar syntax as for module attributes is used for - specifying types and function specifications. + specifying types and function specifications:
-type my_type() :: atom() | integer(). @@ -200,32 +213,36 @@ behaviour_info(callbacks) -> Callbacks.
The description is based on
Comments may be placed anywhere in a module except within strings - and quoted atoms. The comment begins with the character "%", +
Comments can be placed anywhere in a module except within strings + and quoted atoms. A 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 + has no effect. Notice that the terminating end-of-line has the effect of white space.
The compiler automatically inserts the two special, exported
- functions into each module:
These functions can be called to retrieve information + about the module.
The
The The call The call The following values are allowed for Return an atom representing the module name. Returns an atom representing the module name. Return a list of Returns a list of The list of attributes will be empty if
- the module has been stripped with
- The list of attributes becomes empty if
+ the module is stripped with the
+ Return a list of tuples containing information about
- how the module was compiled. This list will be empty if
- the module has been stripped with
- Returns a list of tuples with information about
+ how the module was compiled. This list is empty if
+ the module has been stripped with the
+ Return a binary representing the MD5 checksum of the module. Returns a binary representing the MD5 checksum of the module. Return a list of Returns a list of Return a list of Returns a list of