Bläddra i källkod

ft: 运算符相日志提交

master
lijie 3 år sedan
förälder
incheckning
5f3d78508f
3 ändrade filer med 99 tillägg och 0 borttagningar
  1. +4
    -0
      include/utComMisc.hrl
  2. +74
    -0
      src/docs/erlang/erlang运算符.md
  3. +21
    -0
      src/docs/erlang/etsmatch.hrl.md

+ 4
- 0
include/utComMisc.hrl Visa fil

@ -1,6 +1,10 @@
%%
-define(IIF(Cond, Then, That), case Cond of true -> Then; _ -> That end).
%% IF-DO表达式
-define(IF(IFTure, DoThat), (IFTure) andalso DoThat).
%%unicode编码范围 0x4e00 - 0x9fa5
-define(UNICODE_CHINESE_BEGIN, (4 * 16 * 16 * 16 + 14 * 16 * 16)).
-define(UNICODE_CHINESE_END, (9 * 16 * 16 * 16 + 15 * 16 * 16 + 10 * 16 + 5)).

+ 74
- 0
src/docs/erlang/erlang运算符.md Visa fil

@ -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. = 右到左

+ 21
- 0
src/docs/erlang/etsmatch.hrl.md Visa fil

@ -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(), ... ].

Laddar…
Avbryt
Spara