[英]Colon and Hash operators in Erlang
Erlang文檔提供了具有優先級和關聯性的運算符的完整列表 。
表中的前兩個運算符:
和#
在文檔的其他地方似乎都沒有描述。 從技術上講, #
看起來像地圖更新表達式中的二進制運算符,但這還不是很清楚。 我沒有看到:
運算符的描述,但可能只是錯過了一些東西。
有人對:
和#
運算符有有用的技術描述嗎? (我開始在Erlang語法中查找,但是冒號出現了700多次,因此搜索非常困難。)
對我來說,它只返回14次,遠少於700次:)
:~/otp/lib/stdlib/src % cat erl_parse.yrl | grep "':'"
'(' ')' ',' '->' '{' '}' '[' ']' '|' '||' '<-' ';' ':' '#' '.'
spec_fun -> atom ':' atom : {'$1', '$3'}.
spec_fun -> atom ':' atom '/' integer '::' : {'$1', '$3', '$5'}.
type -> atom ':' atom '(' ')' : {remote_type, ?anno('$1'),
type -> atom ':' atom '(' top_types ')' : {remote_type, ?anno('$1'),
bin_base_type -> var ':' type : build_bin_type(['$1'], '$3').
bin_unit_type -> var ':' var '*' type : build_bin_type(['$1', '$3'], '$5').
expr_800 -> expr_max ':' expr_max :
opt_bit_size_expr -> ':' bit_size_expr : '$2'.
bit_type -> atom ':' integer : { element(3,'$1'), element(3,'$3') }.
fun_expr -> 'fun' atom_or_var ':' atom_or_var '/' integer_or_var :
try_clause -> atom ':' expr clause_guard clause_body :
try_clause -> var ':' expr clause_guard clause_body :
inop_prec(':') -> {900,800,900};
:~/otp/lib/stdlib/src % cat erl_parse.yrl | grep "':'" | wc -l
14
也:
:~/otp/lib/stdlib/src % cat erl_parse.yrl | grep "'#'"
'(' ')' ',' '->' '{' '}' '[' ']' '|' '||' '<-' ';' ':' '#' '.'
type -> '#' '{' '}' : {type, ?anno('$1'), map, []}.
type -> '#' '{' map_pair_types '}' : {type, ?anno('$1'), map, '$3'}.
type -> '#' atom '{' '}' : {type, ?anno('$1'), record, ['$2']}.
type -> '#' atom '{' field_types '}' : {type, ?anno('$1'),
map_expr -> '#' map_tuple :
map_expr -> expr_max '#' map_tuple :
map_expr -> map_expr '#' map_tuple :
record_expr -> '#' atom '.' atom :
record_expr -> '#' atom record_tuple :
record_expr -> expr_max '#' atom '.' atom :
record_expr -> expr_max '#' atom record_tuple :
record_expr -> record_expr '#' atom '.' atom :
record_expr -> record_expr '#' atom record_tuple :
inop_prec('#') -> {800,700,800};
-type pre_op() :: 'catch' | '+' | '-' | 'bnot' | 'not' | '#'.
preop_prec('#') -> {700,800}.
-type type_preop() :: '+' | '-' | 'bnot' | '#'.
type_inop_prec('#') -> {800,700,800}.
type_preop_prec('#') -> {700,800}.
此類信息的確比erl_parse.yrl
。 順便說一句, 這不是我的看法 。
他們都不是正確的操作員。 該文檔在這里具有誤導性。 與16#ffff一樣,#字符用於基本N字面量,但這是在詞匯級別上,在記錄和地圖的語法中,而不是實際的運算符。 :字符用於遠程調用中,就像在list:reverse(Xs)中一樣,但是同樣,它並不是真正的運算符-“ lists:reverse”本身並不是具有值的子表達式。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.