5.1 Module Syntax

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

Example:

  1. -module(m). % module attribute
  2. -export([fact/1]). % module attribute
  3.  
  4. fact(N) when N>0 -> % beginning of function declaration
  5. N * fact(N-1); % |
  6. fact(0) -> % |
  7. 1. % end of function declaration

For a description of function declarations, see Function Declaration Syntax.