[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
7.1 Bigloo pattern matching facilities
Only two special forms are provided for this in Bigloo: match-case
and match-lambda
.
- bigloo syntax: match-case key clause…
The argument key may be any expression and each clause has the form
(pattern s-expression…)
Semantics: A
match-case
expression is evaluated as follows. key is evaluated and the result is compared with each successive pattern. If the pattern in some clause yields a match, then the expressions in that clause are evaluated from left to right in an environment where the pattern variables are bound to the corresponding subparts of the datum, and the result of the last expression in that clause is returned as the result of thematch-case
expression. If no pattern in any clause matches the datum, then, if there is anelse
clause, its expressions are evaluated and the result of the last is the result of the wholematch-case
expression; otherwise the result of thematch-case
expression is unspecified.The equality predicate used is
eq?
.(match-case '(a b a) ((?x ?x) 'foo) ((?x ?- ?x) 'bar)) ⇒ bar
The following syntax is also available:
- bigloo syntax: match-lambda clause…
-
It expands into a lambda-expression expecting an argument which, once applied to an expression, behaves exactly like a
match-case
expression.((match-lambda ((?x ?x) 'foo) ((?x ?- ?x) 'bar)) '(a b a)) ⇒ bar
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated on October 23, 2011 using texi2html 5.0.