Selects a single clause, if possible, or otherwise reduces the list of selectable clauses. The input is a list Clauses
of abstract clauses (i.e., syntax trees of type clause
), and a list of switch expressions Exprs
. The function tries to uniquely select a single clause or discard unselectable clauses, with respect to the switch expressions. All abstract clauses in the list must have the same number of patterns. If Exprs
is not the empty list, it must have the same length as the number of patterns in each clause; see match_list/2
for details.
A clause can only be selected if its guard expression always yields the atom true
, and a clause whose guard expression always yields the atom false
can never be selected. Other guard expressions are considered to have unknown value; cf. eval_guard/1
.
If a particular clause can be selected, the function returns {true, {Clause, Bindings}}
, where Clause
is the selected clause and Bindings
is a list of pairs {Var, SubExpr}
associating the variables occurring in the patterns of Clause
with the corresponding subexpressions in Exprs
. The list of bindings is given in innermost-first order; see the match/2
function for details.
If no clause could be definitely selected, the function returns {false, NewClauses}
, where NewClauses
is the list of entries in Clauses
that remain after eliminating unselectable clauses, preserving the relative order.
See also: eval_guard/1
, match/2
, match_list/2
.