erlang match_spec 解释

链接:http://www.erlang.org/doc/apps/erts/match_spec.html


解释摘要:

A match_spec used in ets can be described in this informal grammar:

  • MatchExpression ::= [ MatchFunction, ... ]
  • MatchFunction ::= { MatchHead, MatchConditions, MatchBody }
  • MatchHead ::= MatchVariable | '_' | { MatchHeadPart, ... }
  • MatchHeadPart ::= term() | MatchVariable | '_'
  • MatchVariable ::= '$<number>'
  • MatchConditions ::= [ MatchCondition, ...] | []
  • MatchCondition ::= { GuardFunction } | { GuardFunction, ConditionExpression, ... }
  • BoolFunction ::= is_atom | is_float | is_integer | is_list | is_number | is_pid | is_port | is_reference | is_tuple | is_binary | is_function | is_record | is_seq_trace | 'and''or' | 'not' | 'xor' | andalso | orelse
  • ConditionExpression ::= ExprMatchVariable | { GuardFunction } | { GuardFunction, ConditionExpression, ... } | TermConstruct
  • ExprMatchVariable ::= MatchVariable (bound in the MatchHead) | '$_' | '$$'
  • TermConstruct = {{}} | {{ ConditionExpression, ... }} | [] | [ConditionExpression, ...] | NonCompositeTerm | Constant
  • NonCompositeTerm ::= term() (not list or tuple)
  • Constant ::= {const, term()}
  • GuardFunction ::= BoolFunction | abs | element | hd | length | node | round | size | tl | trunc | '+' | '-' | '*' | 'div' | 'rem' | 'band' | 'bor' | 'bxor' | 'bnot' | 'bsl' | 'bsr' | '>''>=' | '<' | '=<' | '=:=' | '==' | '=/=' | '/=' | self | get_tcw
  • MatchBody ::= [ ConditionExpression, ... ]

 Variables and literals

Variables take the form '$<number>' where <number> is an integer between 0 (zero) and 100000000 (1e+8), the behavior if the number is outside these limits is undefined. In the MatchHeadpart, the special variable '_' matches anything, and never gets bound (like _ in Erlang). In the MatchCondition/MatchBody parts, no unbound variables are allowed, why '_' is interpreted as itself (an atom). Variables can only be bound in the MatchHead part. In the MatchBody and MatchCondition parts, only variables bound previously may be used. As a special case, in theMatchCondition/MatchBody parts, the variable '$_' expands to the whole expression which matched the MatchHead (i.e., the whole parameter list to the possibly traced function or the whole matching object in the ets table) and the variable '$$' expands to a list of the values of all bound variables in order (i.e. ['$1','$2', ...]).

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值