manpagez: man pages & more
info bigloo
Home | html | info | man
[ << ] [ < ] [ 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 the match-case expression. If no pattern in any clause matches the datum, then, if there is an else clause, its expressions are evaluated and the result of the last is the result of the whole match-case expression; otherwise the result of the match-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.

© manpagez.com 2000-2024
Individual documents may contain additional copyright information.