@ -0,0 +1,74 @@ | |||
# Erlang运算符: | |||
1、算术运算符: +, -, *, /, div, rem, | |||
1、"/", 用于除,但是其结果永远是浮点数, 即不管是否整除 | |||
2、div, 除, 取结果的整数部分 | |||
3、rem, 取模 | |||
2、比较运算符: >, <, >=, =<, ==, =:=, /= , =/= | |||
1、=<, 小于等于 | |||
2、==, 比较两个值是否相等, eg: 1 == 1.0. 结果为: true | |||
3、=:=, 比较两个值是否相等,并且两个对象的类型也必须相等, eg: 1 =:= 1.0. 结果为: false | |||
4、/=, 不相等, eg: 1 /= 1.0. 结果为: false | |||
5、=/=, 不全等, eg: 1 =/= 1.0,结果为: true | |||
3、位运算符:band, bor, bnot, bxor, bsl, bsr | |||
1、band, 位与 | |||
2、bor, 位或 | |||
3、bnot, 位非 | |||
4、bxor, 按位异或 | |||
5、bsl, 按位左移, eg: 1 bsl 5. %将1左移5位,结果为32 | |||
6、bsr, 按位右移 | |||
4、逻辑运算符:(运算符两边的表达式都会计算) | |||
1、not, 逻辑非 | |||
2、and, 逻辑与 | |||
3、or, 逻辑或 | |||
4、xor, 逻辑异或 | |||
5、短路逻辑运算符:(如果前部分能得出结果,就不会计算另一个表达式) | |||
1、andalso , X andalso Y, 如果X为true,则会执行Y,如果X为false,则不会计算Y,直接false | |||
2、orelse, X orelse Y, 如果X为true,则结果为true,不会计算Y | |||
6、运算符优先级: | |||
# 操作符 结合性 | |||
1. : | |||
2. # | |||
3. (一元)+, (一元)-, bnot, not | |||
4. /, * , div, rem, band, and 左到右 | |||
5. +, -, bor, bxor, bsl, bsr, or, xor | |||
6. ++, -- | |||
7. ==, /=, =<, <, >=, =:=, =/= 右到左, 即列表的操作,是将左边加到右边 | |||
8. andalso | |||
9. orelse | |||
10. = 右到左 |
@ -0,0 +1,21 @@ | |||
-type matchExpression() :: [ matchFunction(), ... ]. | |||
-type matchFunction() :: { matchHead(), matchConditions(), matchBody()}. | |||
-type matchHead() :: matchVariable() | '_' | { matchHeadPart(), ...}. | |||
-type matchHeadPart() :: term() | matchVariable() | '_'. | |||
-type matchVariable() :: '$<number>'. | |||
-type matchConditions() :: [ matchCondition(), ...] | []. | |||
-type matchCondition() :: { guardFunction() } | { guardFunction(), conditionExpression(), ... }. | |||
-type boolFunction() :: is_atom | is_float | is_integer | is_list | is_number | is_pid | is_port | is_reference | is_tuple | is_map | map_is_key | is_binary | is_function | is_record | 'and' | 'or' | 'not' | 'xor' | 'andalso' | 'orelse'. | |||
-type conditionExpression() :: exprMatchVariable() | { guardFunction() } | { guardFunction(), conditionExpression(), ... } | termConstruct(). | |||
-type exprMatchVariable() :: matchVariable() (bound in the MatchHead) | '$_' | '$$' | |||
-type termConstruct():: {{}} | {{ conditionExpression(), ... }} | [] | [conditionExpression(), ...] | #{} | #{term() => conditionExpression(), ...} | nonCompositeTerm() | constant(). | |||
-type nonCompositeTerm() :: term(). %% (not list or tuple or map) | |||
-type constant() :: {const, term()}. | |||
-type guardFunction() :: boolFunction() | abs | element | hd | length | map_get | map_size | node | round | size | bit_size | tl | trunc | '+' | '-' | '*' | 'div' | 'rem' | 'band' | 'bor' | 'bxor' | 'bnot' | 'bsl' | 'bsr' | '>' | '>=' | '<' | '=<' | '=:=' | '==' | '=/=' | '/=' | self. | |||
-type matchBody() :: [ conditionExpression(), ... ]. |