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

你可能感兴趣的:(erlang,ets,match_spe)