[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
7.2 The pattern language
The syntax for <pattern> is:
<pattern> → Matches: <atom> the <atom>. | (kwote
<atom>) any expressioneq?
to<atom>
. | (and
<pat1> ... <patn>) if all of<pati>
match. | (or
<pat1> ... ...<patn>) if any of<pat1>
through<patn>
matches. | (not
<pat>) if<pat>
doesn't match. | (?
<predicate>) if<predicate>
is true. | (<pat1> ... <patn>) a list of n elements. Here,...
is a meta-character denoting a finite repetition of patterns. | <pat> ... a (possibly empty) repetition of<pat>
in a list. | #(<pat> ... <patn>) a vector of n elements. | #{<struct> <pat> ... } a structure. |?
<id> anything, and bindsid
as a variable. |?-
anything. |??-
any (possibly empty) repetition of anything in a list. |???-
any end of list.
Remark: and, or, not, check
and kwote
must be
quoted in order to be treated as literals. This is the only justification
for having the kwote
pattern since, by convention, any atom which is
not a keyword is quoted.
-
?-
matches any s-expr -
a
matches the atom'a
. -
?a
matches any expression, and binds the variablea
to this expression. -
(? integer?)
matches any integer -
(a (a b))
matches the only list'(a (a b))
. -
???-
can only appear at the end of a list, and always succeeds. For instance,(a ???-)
is equivalent to(a . ?-)
. - when occurring in a list,
??-
matches any sequence of anything:(a ??- b)
matches any list whosecar
isa
and lastcar
isb
. -
(a ...)
matches any list ofa
’s, possibly empty. -
(?x ?x)
matches any list of length 2 whosecar
is eq to itscadr
-
((and (not a) ?x) ?x)
matches any list of length 2 whosecar
is not eq to'a
but is eq to itscadr
-
#(?- ?- ???-)
matches any vector whose length is at least 2. -
#{foo (?- . ?-) (? integer?)}
matches any structure or recordfoo
whose first and second fields are respectively a pair and an integer. You can provide only the fields you want to test. The order is not relevant.
Remark: ??-
and ...
patterns can not appear
inside a vector, where you should use ???-
: For example,
#(a ??- b)
or #(a...)
are invalid patterns, whereas
#(a ???-)
is valid and matches any vector whose first element
is the atom a
.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated on March 31, 2014 using texi2html 5.0.