aboutsummaryrefslogtreecommitdiffstats
path: root/system/doc/reference_manual
diff options
context:
space:
mode:
Diffstat (limited to 'system/doc/reference_manual')
-rw-r--r--system/doc/reference_manual/book.xml4
-rw-r--r--system/doc/reference_manual/character_set.xml133
-rw-r--r--system/doc/reference_manual/code_loading.xml24
-rw-r--r--system/doc/reference_manual/data_types.xml37
-rw-r--r--system/doc/reference_manual/distributed.xml6
-rw-r--r--system/doc/reference_manual/errors.xml4
-rw-r--r--system/doc/reference_manual/expressions.xml278
-rw-r--r--system/doc/reference_manual/functions.xml4
-rw-r--r--system/doc/reference_manual/introduction.xml87
-rw-r--r--system/doc/reference_manual/macros.xml4
-rw-r--r--system/doc/reference_manual/modules.xml29
-rw-r--r--system/doc/reference_manual/part.xml5
-rw-r--r--system/doc/reference_manual/patterns.xml4
-rw-r--r--system/doc/reference_manual/ports.xml2
-rw-r--r--system/doc/reference_manual/processes.xml8
-rw-r--r--system/doc/reference_manual/records.xml4
-rw-r--r--system/doc/reference_manual/typespec.xml69
17 files changed, 539 insertions, 163 deletions
diff --git a/system/doc/reference_manual/book.xml b/system/doc/reference_manual/book.xml
index eb2e860f80..546fb36a57 100644
--- a/system/doc/reference_manual/book.xml
+++ b/system/doc/reference_manual/book.xml
@@ -1,10 +1,10 @@
-<?xml version="1.0" encoding="latin1" ?>
+<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE book SYSTEM "book.dtd">
<book xmlns:xi="http://www.w3.org/2001/XInclude">
<header titlestyle="normal">
<copyright>
- <year>2003</year><year>2009</year>
+ <year>2003</year><year>2013</year>
<holder>Ericsson AB. All Rights Reserved.</holder>
</copyright>
<legalnotice>
diff --git a/system/doc/reference_manual/character_set.xml b/system/doc/reference_manual/character_set.xml
new file mode 100644
index 0000000000..b09b484582
--- /dev/null
+++ b/system/doc/reference_manual/character_set.xml
@@ -0,0 +1,133 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<!DOCTYPE chapter SYSTEM "chapter.dtd">
+
+<chapter>
+ <header>
+ <copyright>
+ <year>2014</year><year>2014</year>
+ <holder>Ericsson AB. All Rights Reserved.</holder>
+ </copyright>
+ <legalnotice>
+ The contents of this file are subject to the Erlang Public License,
+ Version 1.1, (the "License"); you may not use this file except in
+ compliance with the License. You should have received a copy of the
+ Erlang Public License along with this software. If not, it can be
+ retrieved online at http://www.erlang.org/.
+
+ Software distributed under the License is distributed on an "AS IS"
+ basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ the License for the specific language governing rights and limitations
+ under the License.
+
+ </legalnotice>
+
+ <title>Character Set and Source File Encoding</title>
+ <prepared></prepared>
+ <docno></docno>
+ <date></date>
+ <rev></rev>
+ <file>character_set.xml</file>
+ </header>
+
+ <section>
+ <title>Character Set</title>
+ <p>In Erlang 4.8/OTP R5A the syntax of Erlang tokens was extended to
+ allow the use of the full ISO-8859-1 (Latin-1) character set. This
+ is noticeable in the following ways:</p>
+ <list type="bulleted">
+ <item>
+ <p>All the Latin-1 printable characters can be used and are
+ shown without the escape backslash convention.</p>
+ </item>
+ <item>
+ <p>Atoms and variables can use all Latin-1 letters.</p>
+ </item>
+ </list>
+ <table>
+ <row>
+ <cell align="left" valign="middle"><em>Octal</em></cell>
+ <cell align="left" valign="middle"><em>Decimal</em></cell>
+ <cell align="left" valign="middle">&nbsp;</cell>
+ <cell align="left" valign="middle"><em>Class</em></cell>
+ </row>
+ <row>
+ <cell align="left" valign="middle">200 - 237</cell>
+ <cell align="left" valign="middle">128 - 159</cell>
+ <cell align="left" valign="middle">&nbsp;</cell>
+ <cell align="left" valign="middle">Control characters</cell>
+ </row>
+ <row>
+ <cell align="left" valign="middle">240 - 277</cell>
+ <cell align="left" valign="middle">160 - 191</cell>
+ <cell align="right" valign="middle">- &iquest;</cell>
+ <cell align="left" valign="middle">Punctuation characters</cell>
+ </row>
+ <row>
+ <cell align="left" valign="middle">300 - 326</cell>
+ <cell align="left" valign="middle">192 - 214</cell>
+ <cell align="center" valign="middle">&Agrave; - &Ouml;</cell>
+ <cell align="left" valign="middle">Uppercase letters</cell>
+ </row>
+ <row>
+ <cell align="center" valign="middle">327</cell>
+ <cell align="center" valign="middle">215</cell>
+ <cell align="center" valign="middle">&times;</cell>
+ <cell align="left" valign="middle">Punctuation character</cell>
+ </row>
+ <row>
+ <cell align="left" valign="middle">330 - 336</cell>
+ <cell align="left" valign="middle">216 - 222</cell>
+ <cell align="center" valign="middle">&Oslash; - &THORN;</cell>
+ <cell align="left" valign="middle">Uppercase letters</cell>
+ </row>
+ <row>
+ <cell align="left" valign="middle">337 - 366</cell>
+ <cell align="left" valign="middle">223 - 246</cell>
+ <cell align="center" valign="middle">&szlig; - &ouml;</cell>
+ <cell align="left" valign="middle">Lowercase letters</cell>
+ </row>
+ <row>
+ <cell align="center" valign="middle">367</cell>
+ <cell align="center" valign="middle">247</cell>
+ <cell align="center" valign="middle">&divide;</cell>
+ <cell align="left" valign="middle">Punctuation character</cell>
+ </row>
+ <row>
+ <cell align="left" valign="middle">370 - 377</cell>
+ <cell align="left" valign="middle">248 - 255</cell>
+ <cell align="center" valign="middle">&oslash; - &yuml;</cell>
+ <cell align="left" valign="middle">Lowercase letters</cell>
+ </row>
+ <tcaption>Character Classes.</tcaption>
+ </table>
+ <p>In Erlang/OTP R16B the syntax of Erlang tokens was extended to
+ handle Unicode. The support is limited to
+ string literals and comments. Atoms, module names, and
+ function names are restricted to the ISO-Latin-1 range.
+ More about the usage of Unicode in Erlang source files
+ can be found in <seealso
+ marker="stdlib:unicode_usage#unicode_in_erlang">STDLIB's User's
+ Guide</seealso>.</p>
+ </section>
+ <section>
+ <title>Source File Encoding</title>
+ <p>The Erlang source file <marker
+ id="encoding">encoding</marker> is selected by a
+ comment in one of the first two lines of the source file. The
+ first string that matches the regular expression
+ <c>coding\s*[:=]\s*([-a-zA-Z0-9])+</c> selects the encoding. If
+ the matching string is not a valid encoding it is ignored. The
+ valid encodings are <c>Latin-1</c> and <c>UTF-8</c> where the
+ case of the characters can be chosen freely.</p>
+ <p>The following example selects UTF-8 as default encoding:</p>
+ <pre>
+%% coding: utf-8</pre>
+ <p>Two more examples, both selecting Latin-1 as default encoding:</p>
+ <pre>
+%% For this file we have chosen encoding = Latin-1</pre>
+ <pre>
+%% -*- coding: latin-1 -*-</pre>
+ <p>The default encoding for Erlang source files was changed from
+ Latin-1 to UTF-8 in Erlang OTP 17.0.</p>
+ </section>
+</chapter>
diff --git a/system/doc/reference_manual/code_loading.xml b/system/doc/reference_manual/code_loading.xml
index 0d2d7b2c2f..b5b5704df5 100644
--- a/system/doc/reference_manual/code_loading.xml
+++ b/system/doc/reference_manual/code_loading.xml
@@ -1,10 +1,10 @@
-<?xml version="1.0" encoding="latin1" ?>
+<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE chapter SYSTEM "chapter.dtd">
<chapter>
<header>
<copyright>
- <year>2003</year><year>2011</year>
+ <year>2003</year><year>2014</year>
<holder>Ericsson AB. All Rights Reserved.</holder>
</copyright>
<legalnotice>
@@ -121,10 +121,22 @@ loop() ->
<title>Running a function when a module is loaded</title>
<warning>
- <p>This section describes an experimental feature that was
- introduced in R13B03, and changed in a backwards-incompatible
- way in R13B04. There may be more backward-incompatible changes
- in future releases.</p>
+ <p>The <c>on_load</c> feature should be considered experimental
+ as there are a number of known weak points in current semantics
+ which therefore might also change in future releases:</p>
+ <list>
+ <item><p>Doing external call in on_load to the module itself
+ leads to deadlock.</p></item>
+ <item><p>At module upgrade, other processes calling the module
+ get suspended waiting for on_load to finish. This can be very bad
+ for applications with demands on realtime characteristics.</p></item>
+ <item><p>At module upgrade, no rollback is done if the on_load function fails.
+ The system will be left in a bad limbo state without any working
+ and reachable instance of the module.</p></item>
+ </list>
+ <p>The problems with module upgrade described above could be fixed in future
+ releases by changing the behaviour to not make the module reachable until
+ after the on_load function has successfully returned.</p>
</warning>
<p>The <c>-on_load()</c> directive names a function that should
diff --git a/system/doc/reference_manual/data_types.xml b/system/doc/reference_manual/data_types.xml
index 531d50b2cf..ad92143179 100644
--- a/system/doc/reference_manual/data_types.xml
+++ b/system/doc/reference_manual/data_types.xml
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="latin1" ?>
+<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE chapter SYSTEM "chapter.dtd">
<chapter>
@@ -44,7 +44,8 @@
<list type="bulleted">
<item><c>$</c><em><c>char</c></em> <br></br>
- ASCII value of the character <em><c>char</c></em>.</item>
+ ASCII value or unicode code-point of the character
+ <em><c>char</c></em>.</item>
<item><em><c>base</c></em><c>#</c><em><c>value</c></em> <br></br>
Integer with the base <em><c>base</c></em>, which must be an
@@ -190,6 +191,38 @@ adam
</section>
<section>
+ <title>Map</title>
+ <p>Compound data type with a variable number of key-value associations:</p>
+ <pre>
+#{Key1=>Value1,...,KeyN=>ValueN}</pre>
+ <p>Each key-value association in the map is called an
+ <em>association pair</em>. The key and value parts of the pair are
+ called <em>elements</em>. The number of association pairs is said to be
+ the <em>size</em> of the map.</p>
+ <p>There exists a number of BIFs to manipulate maps.</p>
+ <p>Examples:</p>
+ <pre>
+1> <input>M1 = #{name=>adam,age=>24,date=>{july,29}}.</input>
+#{age => 24,date => {july,29},name => adam}
+2> <input>maps:get(name,M1).</input>
+adam
+3> <input>maps:get(date,M1).</input>
+{july,29}
+4> <input>M2 = maps:update(age,25,M1).</input>
+#{age => 25,date => {july,29},name => adam}
+5> <input>map_size(M).</input>
+3
+6> <input>map_size(#{}).</input>
+0</pre>
+ <p>A collection of maps processing functions can be found in
+ the STDLIB module <seealso marker="stdlib:maps"><c>maps</c></seealso>.</p>
+ <p>Read more about <seealso marker="expressions#map_expressions">Maps</seealso>.</p>
+ <note>
+ <p>Maps are considered experimental during OTP 17.</p>
+ </note>
+ </section>
+
+ <section>
<title>List</title>
<p>Compound data type with a variable number of terms.</p>
<pre>
diff --git a/system/doc/reference_manual/distributed.xml b/system/doc/reference_manual/distributed.xml
index bc55d14c90..88f98bc106 100644
--- a/system/doc/reference_manual/distributed.xml
+++ b/system/doc/reference_manual/distributed.xml
@@ -1,10 +1,10 @@
-<?xml version="1.0" encoding="latin1" ?>
+<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE chapter SYSTEM "chapter.dtd">
<chapter>
<header>
<copyright>
- <year>2003</year><year>2011</year>
+ <year>2003</year><year>2013</year>
<holder>Ericsson AB. All Rights Reserved.</holder>
</copyright>
<legalnotice>
@@ -199,7 +199,7 @@ dilbert@uab</pre>
<cell align="left" valign="middle">Depending on <c>Arg</c>, this function can return a list not only of visible nodes, but also hidden nodes and previously known nodes, etc.</cell>
</row>
<row>
- <cell align="left" valign="middle"><c>set_cookie(Node, Cookie)</c></cell>
+ <cell align="left" valign="middle"><c>erlang:set_cookie(Node, Cookie)</c></cell>
<cell align="left" valign="middle">Sets the magic cookie used when connecting to <c>Node</c>. If <c>Node</c> is the current node, <c>Cookie</c> will be used when connecting to all new nodes.</cell>
</row>
<row>
diff --git a/system/doc/reference_manual/errors.xml b/system/doc/reference_manual/errors.xml
index 4e207021d3..dde6e68f4a 100644
--- a/system/doc/reference_manual/errors.xml
+++ b/system/doc/reference_manual/errors.xml
@@ -1,10 +1,10 @@
-<?xml version="1.0" encoding="latin1" ?>
+<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE chapter SYSTEM "chapter.dtd">
<chapter>
<header>
<copyright>
- <year>2003</year><year>2011</year>
+ <year>2003</year><year>2013</year>
<holder>Ericsson AB. All Rights Reserved.</holder>
</copyright>
<legalnotice>
diff --git a/system/doc/reference_manual/expressions.xml b/system/doc/reference_manual/expressions.xml
index 357f89f731..62a344ad58 100644
--- a/system/doc/reference_manual/expressions.xml
+++ b/system/doc/reference_manual/expressions.xml
@@ -1,10 +1,10 @@
-<?xml version="1.0" encoding="latin1" ?>
+<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE chapter SYSTEM "chapter.dtd">
<chapter>
<header>
<copyright>
- <year>2003</year><year>2012</year>
+ <year>2003</year><year>2013</year>
<holder>Ericsson AB. All Rights Reserved.</holder>
</copyright>
<legalnotice>
@@ -56,7 +56,7 @@ Expr1 + Expr2</code>
<marker id="term"></marker>
<title>Terms</title>
<p>The simplest form of expression is a term, that is an integer,
- float, atom, string, list or tuple.
+ float, atom, string, list, map or tuple.
The return value is the term itself.</p>
</section>
@@ -283,7 +283,7 @@ fun lists:append/2([1,2], [3,4])
length([]) ->
0;
length([H|T]) ->
- 1 + length(T). %% Calls the local funtion length/1
+ 1 + length(T). %% Calls the local function length/1
f(X) when erlang:length(X) > 3 -> %% Calls erlang:length/1,
%% which is allowed in guards
@@ -301,7 +301,7 @@ f(X) when erlang:length(X) > 3 -> %% Calls erlang:length/1,
-import(mod,[length/1]).
-f(X) when erlang:length(X) > 33 -> %% Calls erlang:lenght/1,
+f(X) when erlang:length(X) > 33 -> %% Calls erlang:length/1,
%% which is allowed in guards
erlang:length(X); %% Explicit call to erlang:length in body
@@ -792,6 +792,245 @@ Expr1 -- Expr2</pre>
</section>
<section>
+ <marker id="map_expressions"></marker>
+ <title>Map Expressions</title>
+ <section>
+ <title>Creating Maps</title>
+ <p>
+ Constructing a new map is done by letting an expression <c>K</c> be associated with
+ another expression <c>V</c>:
+ </p>
+ <code>#{ K => V }</code>
+ <p>
+ New maps may include multiple associations at construction by listing every
+ association:
+ </p>
+ <code>#{ K1 => V1, .., Kn => Vn }</code>
+ <p>
+ An empty map is constructed by not associating any terms with each other:
+ </p>
+ <code>#{}</code>
+ <p>
+ All keys and values in the map are terms. Any expression is first evaluated and
+ then the resulting terms are used as <em>key</em> and <em>value</em> respectively.
+ </p>
+ <p>
+ Keys and values are separated by the <c>=></c> arrow and associations are
+ separated by <c>,</c>.
+ </p>
+
+ <p>
+ Examples:
+ </p>
+ <code>
+M0 = #{}, % empty map
+M1 = #{a => &lt;&lt;"hello"&gt;&gt;}, % single association with literals
+M2 = #{1 => 2, b => b}, % multiple associations with literals
+M3 = #{k => {A,B}}, % single association with variables
+M4 = #{{"w", 1} => f()}. % compound key associated with an evaluated expression</code>
+ <p>
+ where, <c>A</c> and <c>B</c> are any expressions and <c>M0</c> through <c>M4</c>
+ are the resulting map terms.
+ </p>
+ <p>
+ If two matching keys are declared, the latter key will take precedence.
+ </p>
+ <p>
+ Example:
+ </p>
+
+<pre>
+1> <input>#{1 => a, 1 => b}.</input>
+#{1 => b }
+2> <input>#{1.0 => a, 1 => b}.</input>
+#{1 => b, 1.0 => a}
+</pre>
+ <p>
+ The order in which the expressions constructing the keys and their
+ associated values are evaluated is not defined. The syntactic order of
+ the key-value pairs in the construction is of no relevance, except in
+ the above mentioned case of two matching keys.
+ </p>
+ </section>
+
+ <section>
+ <title>Updating Maps</title>
+ <p>
+ Updating a map has similar syntax as constructing it.
+ </p>
+ <p>
+ An expression defining the map to be updated is put in front of the expression
+ defining the keys to be updated and their respective values.
+ </p>
+ <code>M#{ K => V }</code>
+ <p>
+ where <c>M</c> is a term of type map and <c>K</c> and <c>V</c> are any expression.
+ </p>
+ <p>
+ If key <c>K</c> does not match any existing key in the map, a new association
+ will be created from key <c>K</c> to value <c>V</c>. If key <c>K</c> matches
+ an existing key in map <c>M</c> its associated value will be replaced by the
+ new value <c>V</c>. In both cases the evaluated map expression will return a new map.
+ </p>
+ <p>
+ If <c>M</c> is not of type map an exception of type <c>badmap</c> is thrown.
+ </p>
+ <p>
+ To only update an existing value, the following syntax is used,
+ </p>
+ <code>M#{ K := V } </code>
+ <p>
+ where <c>M</c> is an term of type map, <c>V</c> is an expression and <c>K</c>
+ is an expression which evaluates to an existing key in <c>M</c>.
+ </p>
+ <p>
+ If key <c>K</c> does not match any existing keys in map <c>M</c> an exception
+ of type <c>badarg</c> will be triggered at runtime. If a matching key <c>K</c>
+ is present in map <c>M</c> its associated value will be replaced by the new
+ value <c>V</c> and the evaluated map expression returns a new map.
+ </p>
+ <p>
+ If <c>M</c> is not of type map an exception of type <c>badmap</c> is thrown.
+ </p>
+ <p>
+ Examples:
+ </p>
+ <code>
+M0 = #{},
+M1 = M0#{a => 0},
+M2 = M1#{a => 1, b => 2},
+M3 = M2#{"function" => fun() -> f() end},
+M4 = M3#{a := 2, b := 3}. % 'a' and 'b' was added in `M1` and `M2`.</code>
+ <p>
+ where <c>M0</c> is any map. It follows that <c>M1 .. M4</c> are maps as well.
+ </p>
+ <p>
+ More Examples:
+ </p>
+<pre>
+1> <input>M = #{1 => a}.</input>
+#{1 => a }
+2> <input>M#{1.0 => b}.</input>
+#{1 => a, 1.0 => b}.
+3> <input>M#{1 := b}.</input>
+#{1 => b}
+4> <input>M#{1.0 := b}.</input>
+** exception error: bad argument
+</pre>
+ <p>
+ As in construction, the order in which the key and value expressions
+ are evaluated is not defined. The
+ syntactic order of the key-value pairs in the update is of no
+ relevance, except in the case where two keys match, in which
+ case the latter value is used.
+ </p>
+ </section>
+
+ <section>
+ <title>Maps in Patterns</title>
+ <p>
+ Matching of key-value associations from maps is done in the following way:
+ </p>
+
+ <code>#{ K := V } = M</code>
+ <p>
+ where <c>M</c> is any map. The key <c>K</c> has to be an expression with bound
+ variables or a literals, and <c>V</c> can be any pattern with either bound or
+ unbound variables.
+ </p>
+ <p>
+ If the variable <c>V</c> is unbound, it will be bound to the value associated
+ with the key <c>K</c>, which has to exist in the map <c>M</c>. If the variable
+ <c>V</c> is bound, it has to match the value associated with <c>K</c> in <c>M</c>.
+ </p>
+ <p> Example: </p>
+<code>
+1> <input>M = #{"tuple" => {1,2}}.</input>
+#{"tuple" => {1,2}}
+2> <input>#{"tuple" := {1,B}} = M.</input>
+#{"tuple" => {1,2}}
+3> <input>B.</input>
+2.</code>
+ <p>
+ This will bind variable <c>B</c> to integer <c>2</c>.
+ </p>
+ <p>
+ Similarly, multiple values from the map may be matched:
+ </p>
+ <code>#{ K1 := V1, .., Kn := Vn } = M</code>
+ <p>
+ where keys <c>K1 .. Kn</c> are any expressions with literals or bound variables. If all
+ keys exist in map <c>M</c> all variables in <c>V1 .. Vn</c> will be matched to the
+ associated values of their respective keys.
+ </p>
+ <p>
+ If the matching conditions are not met, the match will fail, either with
+ </p>
+ <list>
+ <item>
+ a <c>badmatch</c> exception, if used in the context of the matching operator
+ as in the example,
+ </item>
+ <item>
+ or resulting in the next clause being tested in function heads and
+ case expressions.
+ </item>
+ </list>
+ <p>
+ Matching in maps only allows for <c>:=</c> as delimiters of associations.
+ The order in which keys are declared in matching has no relevance.
+ </p>
+ <p>
+ Duplicate keys are allowed in matching and will match each pattern associated
+ to the keys.
+ </p>
+ <code>#{ K := V1, K := V2 } = M</code>
+ <p>
+ Matching an expression against an empty map literal will match its type but
+ no variables will be bound:
+ </p>
+ <code>#{} = Expr</code>
+ <p>
+ This expression will match if the expression <c>Expr</c> is of type map, otherwise
+ it will fail with an exception <c>badmatch</c>.
+ </p>
+ <section>
+ <title>Matching syntax: Example with literals in function heads</title>
+ <p>
+ Matching of literals as keys are allowed in function heads.
+ </p>
+ <code>
+%% only start if not_started
+handle_call(start, From, #{ state := not_started } = S) ->
+...
+ {reply, ok, S#{ state := start }};
+
+%% only change if started
+handle_call(change, From, #{ state := start } = S) ->
+...
+ {reply, ok, S#{ state := changed }};</code>
+ </section>
+ </section>
+ <section>
+ <title>Maps in Guards</title>
+ <p>
+ Maps are allowed in guards as long as all sub-expressions are valid guard expressions.
+ </p>
+ <p>
+ Two guard BIFs handles maps:
+ </p>
+ <list>
+ <item>
+ <seealso marker="erts:erlang#is_map/1">is_map/1</seealso>
+ </item>
+ <item>
+ <seealso marker="erts:erlang#map_size/1">map_size/1</seealso>
+ </item>
+ </list>
+ </section>
+ </section>
+
+ <section>
<marker id="bit_syntax"></marker>
<title>Bit Syntax Expressions</title>
<code type="none"><![CDATA[<<>>
@@ -954,19 +1193,20 @@ Ei = Value |
<title>Fun Expressions</title>
<pre>
fun
- (Pattern11,...,Pattern1N) [when GuardSeq1] ->
- Body1;
+ [Name](Pattern11,...,Pattern1N) [when GuardSeq1] ->
+ Body1;
...;
- (PatternK1,...,PatternKN) [when GuardSeqK] ->
- BodyK
+ [Name](PatternK1,...,PatternKN) [when GuardSeqK] ->
+ BodyK
end</pre>
<p>A fun expression begins with the keyword <c>fun</c> and ends
with the keyword <c>end</c>. Between them should be a function
declaration, similar to a
- <seealso marker="functions#syntax">regular function declaration</seealso>, except that no function name is
- specified.</p>
- <p>Variables in a fun head shadow variables in the
- function clause surrounding the fun expression, and
+ <seealso marker="functions#syntax">regular function declaration</seealso>,
+ except that the function name is optional and should be a variable if
+ any.</p>
+ <p>Variables in a fun head shadow the function name and both shadow
+ variables in the function clause surrounding the fun expression, and
variables bound in a fun body are local to the fun body.</p>
<p>The return value of the expression is the resulting fun.</p>
<p>Examples:</p>
@@ -978,7 +1218,11 @@ end</pre>
3> <input>Fun2 = fun (X) when X>=5 -> gt; (X) -> lt end.</input>
#Fun&lt;erl_eval.6.39074546&gt;
4> <input>Fun2(7).</input>
-gt</pre>
+gt
+5> <input>Fun3 = fun Fact(1) -> 1; Fact(X) when X > 1 -> X * Fact(X - 1) end.</input>
+#Fun&lt;erl_eval.6.39074546&gt;
+6> <input>Fun3(4).</input>
+24</pre>
<p>The following fun expressions are also allowed:</p>
<pre>
fun Name/Arity
@@ -1343,6 +1587,9 @@ end</pre>
<cell align="left" valign="middle"><c>is_list/1</c></cell>
</row>
<row>
+ <cell align="left" valign="middle"><c>is_map/1</c></cell>
+ </row>
+ <row>
<cell align="left" valign="middle"><c>is_number/1</c></cell>
</row>
<row>
@@ -1393,6 +1640,9 @@ end</pre>
<cell align="left" valign="middle"><c>length(List)</c></cell>
</row>
<row>
+ <cell align="left" valign="middle"><c>map_size(Map)</c></cell>
+ </row>
+ <row>
<cell align="left" valign="middle"><c>node()</c></cell>
</row>
<row>
diff --git a/system/doc/reference_manual/functions.xml b/system/doc/reference_manual/functions.xml
index 3746ee6fad..9498ef1402 100644
--- a/system/doc/reference_manual/functions.xml
+++ b/system/doc/reference_manual/functions.xml
@@ -1,10 +1,10 @@
-<?xml version="1.0" encoding="latin1" ?>
+<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE chapter SYSTEM "chapter.dtd">
<chapter>
<header>
<copyright>
- <year>2003</year><year>2009</year>
+ <year>2003</year><year>2013</year>
<holder>Ericsson AB. All Rights Reserved.</holder>
</copyright>
<legalnotice>
diff --git a/system/doc/reference_manual/introduction.xml b/system/doc/reference_manual/introduction.xml
index d143a154b6..36bec17825 100644
--- a/system/doc/reference_manual/introduction.xml
+++ b/system/doc/reference_manual/introduction.xml
@@ -1,10 +1,10 @@
-<?xml version="1.0" encoding="latin1" ?>
+<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE chapter SYSTEM "chapter.dtd">
<chapter>
<header>
<copyright>
- <year>2003</year><year>2013</year>
+ <year>2003</year><year>2014</year>
<holder>Ericsson AB. All Rights Reserved.</holder>
</copyright>
<legalnotice>
@@ -79,88 +79,5 @@
when xor</p>
</section>
- <section>
- <title>Character Set</title>
- <p>In Erlang 4.8/OTP R5A the syntax of Erlang tokens was extended to
- allow the use of the full ISO-8859-1 (Latin-1) character set. This
- is noticeable in the following ways:</p>
- <list type="bulleted">
- <item>
- <p>All the Latin-1 printable characters can be used and are
- shown without the escape backslash convention.</p>
- </item>
- <item>
- <p>Atoms and variables can use all Latin-1 letters.</p>
- </item>
- </list>
- <table>
- <row>
- <cell align="left" valign="middle"><em>Octal</em></cell>
- <cell align="left" valign="middle"><em>Decimal</em></cell>
- <cell align="left" valign="middle">&nbsp;</cell>
- <cell align="left" valign="middle"><em>Class</em></cell>
- </row>
- <row>
- <cell align="left" valign="middle">200 - 237</cell>
- <cell align="left" valign="middle">128 - 159</cell>
- <cell align="left" valign="middle">&nbsp;</cell>
- <cell align="left" valign="middle">Control characters</cell>
- </row>
- <row>
- <cell align="left" valign="middle">240 - 277</cell>
- <cell align="left" valign="middle">160 - 191</cell>
- <cell align="right" valign="middle">- &iquest;</cell>
- <cell align="left" valign="middle">Punctuation characters</cell>
- </row>
- <row>
- <cell align="left" valign="middle">300 - 326</cell>
- <cell align="left" valign="middle">192 - 214</cell>
- <cell align="center" valign="middle">&Agrave; - &Ouml;</cell>
- <cell align="left" valign="middle">Uppercase letters</cell>
- </row>
- <row>
- <cell align="center" valign="middle">327</cell>
- <cell align="center" valign="middle">215</cell>
- <cell align="center" valign="middle">&times;</cell>
- <cell align="left" valign="middle">Punctuation character</cell>
- </row>
- <row>
- <cell align="left" valign="middle">330 - 336</cell>
- <cell align="left" valign="middle">216 - 222</cell>
- <cell align="center" valign="middle">&Oslash; - &THORN;</cell>
- <cell align="left" valign="middle">Uppercase letters</cell>
- </row>
- <row>
- <cell align="left" valign="middle">337 - 366</cell>
- <cell align="left" valign="middle">223 - 246</cell>
- <cell align="center" valign="middle">&szlig; - &ouml;</cell>
- <cell align="left" valign="middle">Lowercase letters</cell>
- </row>
- <row>
- <cell align="center" valign="middle">367</cell>
- <cell align="center" valign="middle">247</cell>
- <cell align="center" valign="middle">&divide;</cell>
- <cell align="left" valign="middle">Punctuation character</cell>
- </row>
- <row>
- <cell align="left" valign="middle">370 - 377</cell>
- <cell align="left" valign="middle">248 - 255</cell>
- <cell align="center" valign="middle">&oslash; - &yuml;</cell>
- <cell align="left" valign="middle">Lowercase letters</cell>
- </row>
- <tcaption>Character Classes.</tcaption>
- </table>
- <p>In Erlang/OTP R16 the syntax of Erlang tokens was extended to
- handle Unicode. To begin with the support is limited to strings,
- but Erlang/OTP R18 is expected to handle Unicode atoms as well.
- More about the usage of Unicode in Erlang source files can be
- found in <seealso
- marker="stdlib:unicode_usage#unicode_in_erlang">STDLIB's User'S
- Guide</seealso>. The default encoding for Erlang source files
- is still Latin-1, but in Erlang/OTP R17 the default encoding
- will be UTF-8. The details on how to state the encoding of an
- Erlang source file can be found in <seealso
- marker="stdlib:epp#encoding">epp(3)</seealso>.</p>
- </section>
</chapter>
diff --git a/system/doc/reference_manual/macros.xml b/system/doc/reference_manual/macros.xml
index ef2db93f94..9fd0b0f287 100644
--- a/system/doc/reference_manual/macros.xml
+++ b/system/doc/reference_manual/macros.xml
@@ -1,10 +1,10 @@
-<?xml version="1.0" encoding="latin1" ?>
+<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE chapter SYSTEM "chapter.dtd">
<chapter>
<header>
<copyright>
- <year>2003</year><year>2011</year>
+ <year>2003</year><year>2013</year>
<holder>Ericsson AB. All Rights Reserved.</holder>
</copyright>
<legalnotice>
diff --git a/system/doc/reference_manual/modules.xml b/system/doc/reference_manual/modules.xml
index 51c8157764..f0ec7ef165 100644
--- a/system/doc/reference_manual/modules.xml
+++ b/system/doc/reference_manual/modules.xml
@@ -1,10 +1,10 @@
-<?xml version="1.0" encoding="latin1" ?>
+<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE chapter SYSTEM "chapter.dtd">
<chapter>
<header>
<copyright>
- <year>2003</year><year>2012</year>
+ <year>2003</year><year>2014</year>
<holder>Ericsson AB. All Rights Reserved.</holder>
</copyright>
<legalnotice>
@@ -53,10 +53,10 @@ fact(0) -> % |
<pre>
-Tag(Value).</pre>
<p><c>Tag</c> must be an atom, while <c>Value</c> must be a literal
- term. As a convenience in user-defined attributes, the literal term
- <c>Value</c> the syntax <c>Name/Arity</c>
- (where <c>Name</c> is an atom and <c>Arity</c> a positive integer)
- will be translated to <c>{Name,Arity}</c>.</p>
+ term. As a convenience in user-defined attributes, if the literal term
+ <c>Value</c> has the syntax <c>Name/Arity</c>
+ (where <c>Name</c> is an atom and <c>Arity</c> a positive integer),
+ the term <c>Name/Arity</c> will be translated to <c>{Name,Arity}</c>.</p>
<p>Any module attribute can be specified. The attributes are stored
in the compiled code and can be retrieved by calling
@@ -134,8 +134,21 @@ fact(0) -> % |
standard behaviours <c>gen_server</c>, <c>gen_fsm</c>,
<c>gen_event</c> or <c>supervisor</c>.</p>
<p>The spelling <c>behavior</c> is also accepted.</p>
- <p>Read more about behaviours and callback modules in OTP Design
- Principles.</p>
+ <p>The callback functions of the module can be specified either
+ directly by the exported function <c>behaviour_info/1</c>:</p>
+ <pre>
+behaviour_info(callbacks) -> Callbacks.</pre>
+ <p>or by a <c>-callback</c> attribute for each callback
+ function:</p>
+ <pre>
+-callback Name(Arguments) -> Result.</pre>
+ <p>where <c>Arguments</c> is a list of zero or more arguments.
+ The <c>-callback</c> attribute is to be preferred since the
+ extra type information can be used by tools to produce
+ documentation or find discrepancies.</p>
+ <p>Read more about behaviours and callback modules in
+ <seealso marker="doc/design_principles:spec_proc#behaviours">
+ OTP Design Principles</seealso>.</p>
</section>
<section>
diff --git a/system/doc/reference_manual/part.xml b/system/doc/reference_manual/part.xml
index 8151f4c4e1..ee8f3dd7eb 100644
--- a/system/doc/reference_manual/part.xml
+++ b/system/doc/reference_manual/part.xml
@@ -1,10 +1,10 @@
-<?xml version="1.0" encoding="latin1" ?>
+<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE part SYSTEM "part.dtd">
<part xmlns:xi="http://www.w3.org/2001/XInclude">
<header>
<copyright>
- <year>2003</year><year>2010</year>
+ <year>2003</year><year>2014</year>
<holder>Ericsson AB. All Rights Reserved.</holder>
</copyright>
<legalnotice>
@@ -28,6 +28,7 @@
<rev></rev>
</header>
<xi:include href="introduction.xml"/>
+ <xi:include href="character_set.xml"/>
<xi:include href="data_types.xml"/>
<xi:include href="patterns.xml"/>
<xi:include href="modules.xml"/>
diff --git a/system/doc/reference_manual/patterns.xml b/system/doc/reference_manual/patterns.xml
index 7289f14d73..1611002fa1 100644
--- a/system/doc/reference_manual/patterns.xml
+++ b/system/doc/reference_manual/patterns.xml
@@ -1,10 +1,10 @@
-<?xml version="1.0" encoding="latin1" ?>
+<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE chapter SYSTEM "chapter.dtd">
<chapter>
<header>
<copyright>
- <year>2003</year><year>2009</year>
+ <year>2003</year><year>2013</year>
<holder>Ericsson AB. All Rights Reserved.</holder>
</copyright>
<legalnotice>
diff --git a/system/doc/reference_manual/ports.xml b/system/doc/reference_manual/ports.xml
index 58e2baac17..621af10624 100644
--- a/system/doc/reference_manual/ports.xml
+++ b/system/doc/reference_manual/ports.xml
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="latin1" ?>
+<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE chapter SYSTEM "chapter.dtd">
<chapter>
diff --git a/system/doc/reference_manual/processes.xml b/system/doc/reference_manual/processes.xml
index 305d7d9c66..95ae0672ec 100644
--- a/system/doc/reference_manual/processes.xml
+++ b/system/doc/reference_manual/processes.xml
@@ -1,10 +1,10 @@
-<?xml version="1.0" encoding="latin1" ?>
+<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE chapter SYSTEM "chapter.dtd">
<chapter>
<header>
<copyright>
- <year>2003</year><year>2009</year>
+ <year>2003</year><year>2013</year>
<holder>Ericsson AB. All Rights Reserved.</holder>
</copyright>
<legalnotice>
@@ -114,8 +114,8 @@ spawn(Module, Name, Args) -> pid()
<p>Two processes can be <em>linked</em> to each other. A link
between two processes <c>Pid1</c> and <c>Pid2</c> is created
by <c>Pid1</c> calling the BIF <c>link(Pid2)</c> (or vice versa).
- There also exists a number a <c>spawn_link</c> BIFs, which spawns
- and links to a process in one operation.</p>
+ There also exist a number of <c>spawn_link</c> BIFs, which spawn
+ and link to a process in one operation.</p>
<p>Links are bidirectional and there can only be one link between
two processes. Repeated calls to <c>link(Pid)</c> have no effect.</p>
<p>A link can be removed by calling the BIF <c>unlink(Pid)</c>.</p>
diff --git a/system/doc/reference_manual/records.xml b/system/doc/reference_manual/records.xml
index d01d883ef3..04766531df 100644
--- a/system/doc/reference_manual/records.xml
+++ b/system/doc/reference_manual/records.xml
@@ -1,10 +1,10 @@
-<?xml version="1.0" encoding="latin1" ?>
+<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE chapter SYSTEM "chapter.dtd">
<chapter>
<header>
<copyright>
- <year>2003</year><year>2010</year>
+ <year>2003</year><year>2013</year>
<holder>Ericsson AB. All Rights Reserved.</holder>
</copyright>
<legalnotice>
diff --git a/system/doc/reference_manual/typespec.xml b/system/doc/reference_manual/typespec.xml
index 1279493ba8..e4aa2ceda6 100644
--- a/system/doc/reference_manual/typespec.xml
+++ b/system/doc/reference_manual/typespec.xml
@@ -1,10 +1,10 @@
-<?xml version="1.0" encoding="iso-8859-1" ?>
+<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE chapter SYSTEM "chapter.dtd">
<chapter>
<header>
<copyright>
- <year>2003</year><year>2013</year>
+ <year>2003</year><year>2014</year>
<holder>Ericsson AB. All Rights Reserved.</holder>
</copyright>
<legalnotice>
@@ -100,9 +100,10 @@
| Fun
| Integer
| List
+ | Map
| Tuple
| Union
- | UserDefined %% described in Section 6.3
+ | UserDefined %% described in Section 7.3
Atom :: atom()
| Erlang_Atom %% 'foo', 'bar', ...
@@ -118,17 +119,25 @@
| fun((TList) -> Type)
Integer :: integer()
- | Erlang_Integer %% ..., -1, 0, 1, ... 42 ...
- | Erlang_Integer..Erlang_Integer %% specifies an integer range
+ | Erlang_Integer %% ..., -1, 0, 1, ... 42 ...
+ | Erlang_Integer..Erlang_Integer %% specifies an integer range
- List :: list(Type) %% Proper list ([]-terminated)
- | improper_list(Type1, Type2) %% Type1=contents, Type2=termination
- | maybe_improper_list(Type1, Type2) %% Type1 and Type2 as above
+ List :: list(Type) %% Proper list ([]-terminated)
+ | maybe_improper_list(Type1, Type2) %% Type1=contents, Type2=termination
+ | nonempty_improper_list(Type1, Type2) %% Type1 and Type2 as above
+ | nonempty_list(Type) %% Proper non-empty list
- Tuple :: tuple() %% stands for a tuple of any size
+ Map :: map() %% stands for a map of any size
+ | #{} %% stands for a map of any size
+ | #{PairList}
+
+ Tuple :: tuple() %% stands for a tuple of any size
| {}
| {TList}
+ PairList :: Type => Type
+ | Type => Type, PairList
+
TList :: Type
| Type, TList
@@ -146,9 +155,8 @@
</p>
<p>
Because lists are commonly used, they have shorthand type notations.
- The type <c>list(T)</c> has the shorthand <c>[T]</c>.
- The shorthand <c>[T,...]</c> stands for
- the set of non-empty proper lists whose elements are of type <c>T</c>.
+ The types <c>list(T)</c> and <c>nonempty_list(T)</c> have the shorthands
+ <c>[T]</c> and <c>[T,...]</c>, respectively.
The only difference between the two shorthands is that <c>[T]</c> may be an
empty list but <c>[T,...]</c> may not.
</p>
@@ -160,7 +168,7 @@
<p>
For convenience, the following types are also built-in.
They can be thought as predefined aliases for the type unions also shown in
- the table. (Some type unions below slightly abuse the syntax of types.)
+ the table.
</p>
<table>
<row>
@@ -170,10 +178,10 @@
<cell><c>term()</c></cell><cell><c>any()</c></cell>
</row>
<row>
- <cell><c>binary()</c></cell><cell><c>&lt;&lt;_:*8&gt;&gt;</c></cell>
+ <cell><c>binary()</c></cell><cell><c>&lt;&lt;_:_*8&gt;&gt;</c></cell>
</row>
<row>
- <cell><c>bitstring()</c></cell><cell><c>&lt;&lt;_:*1&gt;&gt;</c></cell>
+ <cell><c>bitstring()</c></cell><cell><c>&lt;&lt;_:_*1&gt;&gt;</c></cell>
</row>
<row>
<cell><c>boolean()</c></cell><cell><c>'false' | 'true'</c></cell>
@@ -194,7 +202,7 @@
<cell><c>maybe_improper_list()</c></cell><cell><c>maybe_improper_list(any(), any())</c></cell>
</row>
<row>
- <cell><c>maybe_improper_list(T)</c></cell><cell><c>maybe_improper_list(T, any())</c></cell>
+ <cell><c>nonempty_list()</c></cell><cell><c>nonempty_list(any())</c></cell>
</row>
<row>
<cell><c>string()</c></cell><cell><c>[char()]</c></cell>
@@ -203,13 +211,22 @@
<cell><c>nonempty_string()</c></cell><cell><c>[char(),...]</c></cell>
</row>
<row>
+ <cell><c>iodata()</c></cell><cell><c>iolist() | binary()</c></cell>
+ </row>
+ <row>
<cell><c>iolist()</c></cell><cell><c>maybe_improper_list(byte() | binary() | iolist(), binary() | [])</c></cell>
</row>
<row>
+ <cell><c>function()</c></cell><cell><c>fun()</c></cell>
+ </row>
+ <row>
<cell><c>module()</c></cell><cell><c>atom()</c></cell>
</row>
<row>
- <cell><c>mfa()</c></cell><cell><c>{atom(),atom(),byte()}</c></cell>
+ <cell><c>mfa()</c></cell><cell><c>{atom(),atom(),arity()}</c></cell>
+ </row>
+ <row>
+ <cell><c>arity()</c></cell><cell><c>0..255</c></cell>
</row>
<row>
<cell><c>node()</c></cell><cell><c>atom()</c></cell>
@@ -245,24 +262,20 @@
Users are not allowed to define types with the same names as the
predefined or built-in ones. This is checked by the compiler and
its violation results in a compilation error.
- (For bootstrapping purposes, it can also result to just a warning
- if this involves a built-in type which has just been introduced.)
</p>
<note>
The following built-in list types also exist,
but they are expected to be rarely used. Hence, they have long names:
</note>
<pre>
- nonempty_maybe_improper_list(Type) :: nonempty_maybe_improper_list(Type, any())
- nonempty_maybe_improper_list() :: nonempty_maybe_improper_list(any())</pre>
- <p>
- where the following two types
- define the set of Erlang terms one would expect:
- </p>
- <pre>
+ nonempty_maybe_improper_list() :: nonempty_maybe_improper_list(any(), any())
nonempty_improper_list(Type1, Type2)
nonempty_maybe_improper_list(Type1, Type2)</pre>
<p>
+ where the last two types
+ define the set of Erlang terms one would expect.
+ </p>
+ <p>
Also for convenience, we allow for record notation to be used.
Records are just shorthands for the corresponding tuples.
</p>
@@ -273,6 +286,10 @@
Records have been extended to possibly contain type information.
This is described in the sub-section <seealso marker="#typeinrecords">"Type information in record declarations"</seealso> below.
</p>
+ <note>
+ <p>Map types, both <c>map()</c> and <c>#{ ... }</c>, are considered experimental during OTP 17.</p>
+ <p>No type information of maps pairs, only the containing map types, are used by Dialyzer in OTP 17.</p>
+ </note>
</section>
<section>