From 767a7cfa99dc454da9d2712b3a5f2dd1c1c89165 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn-Egil=20Dahlberg?= Date: Tue, 8 Sep 2015 12:19:49 +0200 Subject: doc: Update term comparison with Maps --- system/doc/reference_manual/expressions.xml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'system/doc/reference_manual/expressions.xml') diff --git a/system/doc/reference_manual/expressions.xml b/system/doc/reference_manual/expressions.xml index 668a51d6bc..893398b71b 100644 --- a/system/doc/reference_manual/expressions.xml +++ b/system/doc/reference_manual/expressions.xml @@ -568,10 +568,14 @@ Expr1 op Expr2

The arguments can be of different data types. The following order is defined:

-number < atom < reference < fun < port < pid < tuple < list < bit string
+number < atom < reference < fun < port < pid < tuple < map < nil < list < bit string

Lists are compared element by element. Tuples are ordered by size, two tuples with the same size are compared element by element.

+

Maps are ordered by size, two maps with the same size are compared by keys in + ascending term order and then by values in key order. + In maps key order integers types are considered less than floats types. +

When comparing an integer to a float, the term with the lesser precision is converted into the type of the other term, unless the operator is one of =:= or =/=. A float is more precise than @@ -591,7 +595,11 @@ true 2> 1=:=1.0. false 3> 1 > a. -false +false +4> #{c => 3} > #{a => 1, b => 2}. +false +4> #{a => 1, b => 2} == #{a => 1.0, b => 2.0}. +true

-- cgit v1.2.3 From 39dc426b3ee91cb1d2628f217c83147354663cc0 Mon Sep 17 00:00:00 2001 From: Hans Bolinder Date: Wed, 16 Dec 2015 14:31:41 +0100 Subject: doc: Update a refman example --- system/doc/reference_manual/expressions.xml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'system/doc/reference_manual/expressions.xml') diff --git a/system/doc/reference_manual/expressions.xml b/system/doc/reference_manual/expressions.xml index 893398b71b..e98fcbcbb9 100644 --- a/system/doc/reference_manual/expressions.xml +++ b/system/doc/reference_manual/expressions.xml @@ -245,13 +245,13 @@ lists:keysearch(Name, 1, List) handle(Msg, State) spawn(m, init, [])

Examples where ExprF is a fun:

- -Fun1 = fun(X) -> X+1 end -Fun1(3) -=> 4 - -fun lists:append/2([1,2], [3,4]) -=> [1,2,3,4] +
+1> Fun1 = fun(X) -> X+1 end,
+Fun1(3).
+4
+2> fun lists:append/2([1,2], [3,4]).
+[1,2,3,4]
+3> 

Notice that when calling a local function, there is a difference between using the implicitly or fully qualified function name. @@ -1004,7 +1004,7 @@ M4 = M3#{a := 2, b := 3}. % 'a' and 'b' was added in `M1` and `M2`.

A badmatch exception.

-

This is if it is used in the context of the matching operator +

This is if it is used in the context of the match operator as in the example.

Or resulting in the next clause being tested in function heads and @@ -1085,7 +1085,7 @@ Ei = Value |

Used in a bit string construction, Value is an expression that is to evaluate to an integer, float, or bit string. If the expression is not a single literal or variable, it - is to be enclosed in parenthesis.

+ is to be enclosed in parentheses.

Used in a bit string matching, Value must be a variable, or an integer, float, or string.

@@ -1319,7 +1319,7 @@ catch Expr {'EXIT',{badarith,[...]}}

Notice that catch has low precedence and catch subexpressions often needs to be enclosed in a block - expression or in parenthesis:

+ expression or in parentheses:

 3> A = catch 1+2.
 ** 1: syntax error before: 'catch' **
-- 
cgit v1.2.3