Skip to content
Newer
Older
100644 1038 lines (625 sloc) 22 KB
a0e94a1 Documentation.
Tomohiro Matsuyama authored
1 optima - Optimized Pattern Matching Library
457d6a0 Documentation.
Tomohiro Matsuyama authored
2 ===========================================
3
6f7d4d0 @m2ym Sync doc
authored
4 optima is a fast pattern matching library which
5 uses optimizing techniques widely used in the functional programming
6 world. See the following references for more details:
457d6a0 Documentation.
Tomohiro Matsuyama authored
7
8 * [Optimizing Pattern Matching](http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.6.5507) by Fabrice Le Fessant, Luc Maranget
9 * [The Implementation of Functional Programming Languages](http://research.microsoft.com/en-us/um/people/simonpj/papers/slpj-book-1987/) by Simon Peyton Jones
10
e7b2731 Documentation.
Tomohiro Matsuyama authored
11 Pattern Language
12 ----------------
457d6a0 Documentation.
Tomohiro Matsuyama authored
13
3f6ccd0 @malisper Cleaned up grammar and spelling in documentation.
malisper authored
14 A pattern specifier, or a pattern for short ambiguous, is an
6f7d4d0 @m2ym Sync doc
authored
15 expression that describes how a value matches some
16 specification. Pattern specifiers are defined as follows:
457d6a0 Documentation.
Tomohiro Matsuyama authored
17
18 pattern-specifier ::= constant-pattern
19 | variable-pattern
4da8aa6 Rename symbol-pattern to symbol-pattern
Tomohiro Matsuyama authored
20 | place-pattern
457d6a0 Documentation.
Tomohiro Matsuyama authored
21 | guard-pattern
5d7bd23 Added not-pattern.
Tomohiro Matsuyama authored
22 | not-pattern
8384037 Added or-pattern.
Tomohiro Matsuyama authored
23 | or-pattern
7c6ef9b Added AND pattern, removed AS pattern.
Tomohiro Matsuyama authored
24 | and-pattern
24af190 Refactor constructor pattern parser/compiler
Tomohiro Matsuyama authored
25 | constructor-pattern
1ded97b Improve guard pattern.
Tomohiro Matsuyama authored
26 | derived-pattern
457d6a0 Documentation.
Tomohiro Matsuyama authored
27 constant-pattern ::= t | nil
056a142 Fix documentation
Tomohiro Matsuyama authored
28 | keyword
457d6a0 Documentation.
Tomohiro Matsuyama authored
29 | atom-except-symbol
30 | (quote VALUE)
68f9468 Added smatch family.
Tomohiro Matsuyama authored
31 variable-pattern ::= SYMBOL | (variable SYMBOL)
4da8aa6 Rename symbol-pattern to symbol-pattern
Tomohiro Matsuyama authored
32 place-pattern ::= (place SYMBOL)
1ded97b Improve guard pattern.
Tomohiro Matsuyama authored
33 guard-pattern ::= (guard PATTERN TEST-FORM)
5d7bd23 Added not-pattern.
Tomohiro Matsuyama authored
34 not-pattern ::= (not PATTERN)
8384037 Added or-pattern.
Tomohiro Matsuyama authored
35 or-pattern ::= (or PATTERN*)
7c6ef9b Added AND pattern, removed AS pattern.
Tomohiro Matsuyama authored
36 and-pattern ::= (and PATTERN*)
24af190 Refactor constructor pattern parser/compiler
Tomohiro Matsuyama authored
37 constructor-pattern ::= (NAME ARG*)
1ded97b Improve guard pattern.
Tomohiro Matsuyama authored
38 derived-pattern ::= (NAME PATTERN*)
457d6a0 Documentation.
Tomohiro Matsuyama authored
39
43ae275 Added as-pattern.
Tomohiro Matsuyama authored
40 ### Constant-Pattern
e7b2731 Documentation.
Tomohiro Matsuyama authored
41
43ae275 Added as-pattern.
Tomohiro Matsuyama authored
42 A constant-pattern matches the constant itself.
457d6a0 Documentation.
Tomohiro Matsuyama authored
43
44 Examples:
45
46 (match 1 (1 2)) => 2
47 (match "foo" ("foo" "bar")) => "bar"
48 (match '(1) ('(1) 2)) => 2
49
43ae275 Added as-pattern.
Tomohiro Matsuyama authored
50 ### Variable-Pattern
e7b2731 Documentation.
Tomohiro Matsuyama authored
51
11f6e25 Minor edits.
Robert P. Goldman authored
52 A variable-pattern matches any value and binds the value to the
53 variable. "_" and "otherwise" are special variable-patterns (a.k.a
3f6ccd0 @malisper Cleaned up grammar and spelling in documentation.
malisper authored
54 wildcard-pattern) which match any value but don't bind.
457d6a0 Documentation.
Tomohiro Matsuyama authored
55
56 Examples:
57
58 (match 1 (x x)) => 1
59 (match 1 (_ 2)) => 2
5d7bd23 Added not-pattern.
Tomohiro Matsuyama authored
60 (match 1
61 (2 2)
62 (otherwise 'otherwise))
63 => OTHERWISE
457d6a0 Documentation.
Tomohiro Matsuyama authored
64
4da8aa6 Rename symbol-pattern to symbol-pattern
Tomohiro Matsuyama authored
65 ### Place-Pattern
0299149 Added SYMBOL-MACRO pattern.
Tomohiro Matsuyama authored
66
3f6ccd0 @malisper Cleaned up grammar and spelling in documentation.
malisper authored
67 A place-pattern matches any value, in the same way as
68 variable-patterns do, but binds the value by using SYMBOL-MACROLET.
0299149 Added SYMBOL-MACRO pattern.
Tomohiro Matsuyama authored
69
70 Examples:
71
72 (defvar c (cons 1 2))
4da8aa6 Rename symbol-pattern to symbol-pattern
Tomohiro Matsuyama authored
73 (match c ((cons (place x) y) (incf x) (incf y)))
1257b2e Added a structure constructor pattern.
Tomohiro Matsuyama authored
74 c
75 => (2 . 2)
0299149 Added SYMBOL-MACRO pattern.
Tomohiro Matsuyama authored
76
24af190 Refactor constructor pattern parser/compiler
Tomohiro Matsuyama authored
77 ### Guard-Pattern
78
3f6ccd0 @malisper Cleaned up grammar and spelling in documentation.
malisper authored
79 A guard-pattern is a special pattern that tests whether TEST-FORM is
80 satisfied in the current matching context.
24af190 Refactor constructor pattern parser/compiler
Tomohiro Matsuyama authored
81
82 Examples:
83
84 (match 1 ((guard x (eql x 2)) t))
85 => NIL
86 (match 1 ((guard x (eql x 1)) t))
87 => T
88
89 ### Not-Pattern
90
91 A not-pattern matches a value that is not matched with sub-PATTERN.
92
93 Examples:
94
95 (match 1 ((not 2) 3)) => 3
96 (match 1 ((not (not 1)) 1)) => 1
97
98 ### Or-Pattern
99
100 An or-pattern matches a value that is matched with one of
ece076c Fix doc
Tomohiro Matsuyama authored
101 sub-PATTERNs.
24af190 Refactor constructor pattern parser/compiler
Tomohiro Matsuyama authored
102
103 Examples:
104
105 (match '(2 . 1) ((or (cons 1 x) (cons 2 x)) x))
106 => 1
107
108 ### And-Pattern
109
11f6e25 Minor edits.
Robert P. Goldman authored
110 An and-pattern matches a value that is matched with all of its
24af190 Refactor constructor pattern parser/compiler
Tomohiro Matsuyama authored
111 sub-PATTERNs. The most common use case is to match a value and bind
112 the value to a variable.
113
114 Examples:
115
116 (match 1 ((and 1 x) x))
117 => 1
118
43ae275 Added as-pattern.
Tomohiro Matsuyama authored
119 ### Constructor-Pattern
457d6a0 Documentation.
Tomohiro Matsuyama authored
120
3f6ccd0 @malisper Cleaned up grammar and spelling in documentation.
malisper authored
121 A constructor-pattern matches the sub-components of a value based on
122 its structure. The following constructors are available:
e7b2731 Documentation.
Tomohiro Matsuyama authored
123
1257b2e Added a structure constructor pattern.
Tomohiro Matsuyama authored
124 #### CONS
125
126 Syntax:
127
128 cons-constructor-pattern ::= (cons CAR-PATTERN CDR-PATTERN)
457d6a0 Documentation.
Tomohiro Matsuyama authored
129
130 Examples:
131
1257b2e Added a structure constructor pattern.
Tomohiro Matsuyama authored
132 (match '(1 . 2)
133 ((cons a b) (+ a b)))
134 => 3
457d6a0 Documentation.
Tomohiro Matsuyama authored
135
2475a18 Add ASSOC and PASSOC patterns
Tomohiro Matsuyama authored
136 #### ASSOC
137
138 Syntax:
139
01ac1fc Rename PASSOC to PROPERTY and export
Tomohiro Matsuyama authored
140 assoc-constructor-pattern ::= (assoc ITEM PATTERN &key key test)
2475a18 Add ASSOC and PASSOC patterns
Tomohiro Matsuyama authored
141
142 Examples:
143
144 (match '((1 . :one))
145 ((assoc 1 x) x))
146 => :ONE
147 (match '((1 . :one) (2 . :two))
148 ((assoc 2 x) x))
149 => :TWO
150 (match '(1 (2 . 3))
151 ((assoc 2 x) x))
152 => 3
153 (match '(("a" . 123))
154 ((assoc "A" 123 :test #'string-equal) t))
155 => T
156
01ac1fc Rename PASSOC to PROPERTY and export
Tomohiro Matsuyama authored
157 #### PROPERTY
158
159 Syntax:
160
161 property-constructor-pattern ::= (property KEY PATTERN)
162
163 Examples:
164
165 (match '(:a 1)
166 ((property :a x) x))
167 => 1
168 (match '(:a 1 :b 2)
169 ((property :b x) x))
170 => 2
171 (match '(:a 1 2)
172 ((property :a x) x))
173 => 1
174
1257b2e Added a structure constructor pattern.
Tomohiro Matsuyama authored
175 #### VECTOR
457d6a0 Documentation.
Tomohiro Matsuyama authored
176
1257b2e Added a structure constructor pattern.
Tomohiro Matsuyama authored
177 Syntax:
457d6a0 Documentation.
Tomohiro Matsuyama authored
178
1257b2e Added a structure constructor pattern.
Tomohiro Matsuyama authored
179 vector-constructor-pattern ::= (vector PATTERN*)
457d6a0 Documentation.
Tomohiro Matsuyama authored
180
181 Examples:
182
1257b2e Added a structure constructor pattern.
Tomohiro Matsuyama authored
183 (match #(1 2)
184 ((vector a b) (+ a b)))
185 => 3
186
187 #### SIMPLE-VECTOR
188
189 Syntax:
190
191 simple-vector-constructor-pattern ::= (simple-vector PATTERN*)
192
193 Examples:
194
195 (match #(1 2)
196 ((simple-vector a b) (+ a b)))
197 => 3
198
199 #### CLASS
200
1208054 Added defun-match family plus documentation fix.
Tomohiro Matsuyama authored
201 Matches an instance of a given subclass of standard-class, as well as
202 the instance's slots.
1257b2e Added a structure constructor pattern.
Tomohiro Matsuyama authored
203
204 Syntax:
205
206 class-constructor-pattern ::= (class NAME slot*)
207 | (NAME slot*)
208 slot ::= SLOT-NAME
209 | (SLOT-NAME PATTERN*)
210
211 CLASS can be omitted. If slot is a symbol, then it will be regarded
11f6e25 Minor edits.
Robert P. Goldman authored
212 as (slot slot). If more than one PATTERN is given, then they will be
1257b2e Added a structure constructor pattern.
Tomohiro Matsuyama authored
213 wrapped by and-pattern like (and PATTERN*).
214
215 Examples:
216
217 (defclass point ()
218 ((x :initarg :x)
219 (y :initarg :y)))
220 (defvar p (make-instance 'point :x 1 :y 2))
221 (match p
222 ((point x y) (list x y)))
223 => (1 2)
224 (match p
3143571 Updated README.
Josh Marchán authored
225 ((point (x 1 x)) x))
1257b2e Added a structure constructor pattern.
Tomohiro Matsuyama authored
226 => 1
227 (defstruct person (name age))
457d6a0 Documentation.
Tomohiro Matsuyama authored
228 (defvar foo (make-person :name "foo" :age 30))
229 (match foo
230 ((person name age) (list name age)))
231 => ("foo" 30)
1257b2e Added a structure constructor pattern.
Tomohiro Matsuyama authored
232
a73d55c Introduce MAKE-INSTANCE style pattern syntax
Tomohiro Matsuyama authored
233 You can also use MAKE-INSTANCE style pattern syntax like:
234
235 (match foo
236 ((person :name name :age age) (list name age)))
237 => ("foo" 30)
238
239 This is equal to the example above except this implicitly resolves the
3f6ccd0 @malisper Cleaned up grammar and spelling in documentation.
malisper authored
240 slot names using the Metaobject Protocol. In this case, you have to
241 make sure the slot names can be determined uniquely during the
242 compilation. Otherwise, you will get a compiler error.
a73d55c Introduce MAKE-INSTANCE style pattern syntax
Tomohiro Matsuyama authored
243
1257b2e Added a structure constructor pattern.
Tomohiro Matsuyama authored
244 #### STRUCTURE
245
3143571 Updated README.
Josh Marchán authored
246 Matches any structure value, and its slot values.
1257b2e Added a structure constructor pattern.
Tomohiro Matsuyama authored
247
248 Syntax:
249
250 structure-constructor-pattern ::= (structure CONC-NAME slot*)
251 | (CONC-NAME slot*)
252 slot ::= SLOT-NAME
253 | (SLOT-NAME PATTERN*)
254
6f7d4d0 @m2ym Sync doc
authored
255 As in the CLASS constructor-pattern, STRUCTURE can be
256 omitted. CONC-NAME is a prefix string of a predicate (CONC-NAME +
257 "p") and accessors (CONC-NAME + SLOT-NAME). For example, if we have
258 the following defstruct,
1257b2e Added a structure constructor pattern.
Tomohiro Matsuyama authored
259
260 (defstruct person name age)
261
262 the structure constructor-pattern (person- name age) is valid because
263 PERSON-P, PERSON-NAME and PERSON-AGE are available here. Technically,
3f6ccd0 @malisper Cleaned up grammar and spelling in documentation.
malisper authored
264 we don't need an actual structure definition. If we have the following
265 code, for instance,
1257b2e Added a structure constructor pattern.
Tomohiro Matsuyama authored
266
267 (defun point-p (p) (consp p))
268 (defun point-x (p) (car p))
269 (defun point-y (p) (cdr p))
270
271 the pattern matching below is valid.
272
273 (match (cons 1 2)
274 ((point- x y) (list x y)))
275 => (1 2)
276
277 Examples:
278
279 (defstruct (person (:conc-name :p-)
280 (:predicate p-p))
281 name age)
282 (match (make-person :name "foo" :age 30)
283 ((p- name age) (list name age)))
284 => ("foo" 30)
457d6a0 Documentation.
Tomohiro Matsuyama authored
285
11f6e25 Minor edits.
Robert P. Goldman authored
286 As in the class constructor-pattern, you can also use MAKE-INSTANCE
a73d55c Introduce MAKE-INSTANCE style pattern syntax
Tomohiro Matsuyama authored
287 style pattern syntax like:
288
289 (match (cons 1 2)
290 ((point- :x x :y y) (list x y)))
291 => (1 2)
292
1ded97b Improve guard pattern.
Tomohiro Matsuyama authored
293 ### Derived-Pattern
294
295 A derived-pattern is a pattern that is defined with DEFPATTERN. There
3f6ccd0 @malisper Cleaned up grammar and spelling in documentation.
malisper authored
296 are some builtin derived patterns as below:
1ded97b Improve guard pattern.
Tomohiro Matsuyama authored
297
298 #### LIST
299
8a7b1f3 Add a reference to fare-quasiquote-optima
Tomohiro Matsuyama authored
300 Expansion of LIST derived patterns:
1ded97b Improve guard pattern.
Tomohiro Matsuyama authored
301
302 (list a b c) => (cons a (cons b (cons c nil)))
303
304 #### LIST*
305
306 Expansion of LIST* derived patterns:
307
8a7b1f3 Add a reference to fare-quasiquote-optima
Tomohiro Matsuyama authored
308 (list* a b c) => (cons a (cons b c))
1ded97b Improve guard pattern.
Tomohiro Matsuyama authored
309
310 #### SATISFIES
311
312 Expansion of SATISFIES derived patterns:
313
0666333 Remove WHEN/UNLESS pattern
Tomohiro Matsuyama authored
314 (satisfies f) => (guard it (f it))
1ded97b Improve guard pattern.
Tomohiro Matsuyama authored
315
316 #### EQ, EQL, EQUAL, EQUALP
317
318 Expansion of EQ, EQL, EQUAL, EQUALP derived patterns:
319
0666333 Remove WHEN/UNLESS pattern
Tomohiro Matsuyama authored
320 (eq 'foo) => (guard it (eq it 'foo))
321 (eql 123) => (guard it (eql it 123))
322 (equal '(1 2)) => (guard it (equal it '(1 2)))
323 (equalp "foo") => (guard it (equalp it "foo"))
1ded97b Improve guard pattern.
Tomohiro Matsuyama authored
324
9c07dbe Rename TYPEP pattern to TYPE
Tomohiro Matsuyama authored
325 #### TYPE
1ded97b Improve guard pattern.
Tomohiro Matsuyama authored
326
9c07dbe Rename TYPEP pattern to TYPE
Tomohiro Matsuyama authored
327 Expansion of TYPE derived patterns:
1ded97b Improve guard pattern.
Tomohiro Matsuyama authored
328
8a7b1f3 Add a reference to fare-quasiquote-optima
Tomohiro Matsuyama authored
329 (TYPE type) => (guard it (typep it 'type))
330
331 Quasiquotation
332 --------------
333
334 You may want to use a quasiquote in a pattern specifier like:
335
336 (match '(1 2 3 4)
337 (`(1 ,x ,@y) (list x y)))
338
339 To do so, you need to use a specific quasiquote reader, for example
11f6e25 Minor edits.
Robert P. Goldman authored
340 [fare-quasiquote](http://cliki.net/fare-quasiquote) , loading
6f7d4d0 @m2ym Sync doc
authored
341 fare-quasiquote-optima system, because there is no standard expanded
342 form for quasiquote expressions.
1ded97b Improve guard pattern.
Tomohiro Matsuyama authored
343
dea6d2d Add optima.core package
Tomohiro Matsuyama authored
344 Define Constructor Patterns
345 ---------------------------
346
3f6ccd0 @malisper Cleaned up grammar and spelling in documentation.
malisper authored
347 You can define your own constructor patterns by using the
6f7d4d0 @m2ym Sync doc
authored
348 `OPTIMA.CORE` package. First, define a data structure for the
3f6ccd0 @malisper Cleaned up grammar and spelling in documentation.
malisper authored
349 constructor pattern.
dea6d2d Add optima.core package
Tomohiro Matsuyama authored
350
351 (defstruct (my-cons-pattern (:include constructor-pattern)
352 (:constructor make-cons-pattern (car-pattern cdr-pattern
353 &aux (subpatterns (list car-pattern
354 cdr-pattern))))))
355
356 Note that you must keep `SUBPATTERNS` of the constructor pattern in
11f6e25 Minor edits.
Robert P. Goldman authored
357 sync so that optima can take care of them.
358
3f6ccd0 @malisper Cleaned up grammar and spelling in documentation.
malisper authored
359 Second, specify a condition for when the destructor of two constructor
360 patterns can be shared. This makes it possible to perform some
361 optimizations.
dea6d2d Add optima.core package
Tomohiro Matsuyama authored
362
363 (defmethod constructor-pattern-destructor-sharable-p ((x my-cons-pattern) (y my-cons-pattern))
364 t)
365
3f6ccd0 @malisper Cleaned up grammar and spelling in documentation.
malisper authored
366 Third, define a destructor generator for the constructor pattern. The
367 destructor generator will make a destructor that specifies how to
6f7d4d0 @m2ym Sync doc
authored
368 check the the data (`PREDICATE-FORM`) and how to access the
369 data (`ACCESSOR-FORMS`).
dea6d2d Add optima.core package
Tomohiro Matsuyama authored
370
371 (defmethod constructor-pattern-make-destructor ((pattern my-cons-pattern) var)
372 (make-destructor :predicate-form `(consp ,var)
373 :accessor-forms (list `(car ,var) `(cdr ,var))))
374
375 Finally, define a parser and an unparser for the constructor pattern.
376
377 (defmethod parse-constructor-pattern ((name (eql 'my-cons)) &rest args)
378 (apply #'make-my-cons-pattern (mapcar #'parse-pattern args)))
379 (defmethod unparse-pattern ((pattern my-cons-pattern))
380 `(cons ,(unparse-pattern (my-cons-pattern-car-pattern pattern))
381 ,(unparse-pattern (my-cons-pattern-cdr-pattern pattern))))
382
383 See the source code for more detail.
384
385 [Package] optima.core
386 ---------------------
387
388 ### [Function] %equal
389
390 %equal a b
391
3f6ccd0 @malisper Cleaned up grammar and spelling in documentation.
malisper authored
392 Equality function for comparing pattern constants.
dea6d2d Add optima.core package
Tomohiro Matsuyama authored
393
394 ### [Macro] %equals
395
396 %equals var value
397
398 Equality macro for comparing pattern constants. This specializes
399 the comparison form to some specific form as follows:
400
401 (equals x nil) => (null x)
402 (equals x 'foo) => (eq x 'foo)
403 (equals x 123) => (eql x 123)
404 (equals x '(a b)) => (%equals x '(a b))
405
406 ### [Function] %svref
407
408 %svref simple-vector index
409
410 Safe SVREF.
411
412 ### [Function] %assoc
413
414 %assoc item alist &key (test #'eql)
415
416 Safe ASSOC.
417
418 ### [Function] %get-property
419
420 %get-property item plist
421
422 Safe GETF.
423
424 ### [Class] destructor
425
426 ### [Type] destructor
427
428 destructor
429
430 ### [Function] destructor-accessor-forms
431
432 destructor-accessor-forms instance
433
434 ### [Function] make-destructor
435
3aba00d @m2ym Fix compilation error
authored
436 make-destructor &key ((bindings bindings) nil) ((predicate-form predicate-form)
437 nil) ((accessor-forms
438 accessor-forms)
439 nil)
dea6d2d Add optima.core package
Tomohiro Matsuyama authored
440
441 ### [Class] variable-pattern
442
443 ### [Type] variable-pattern
444
445 variable-pattern
446
447 ### [Function] variable-pattern-name
448
449 variable-pattern-name instance
450
451 ### [Function] make-variable-pattern
452
453 make-variable-pattern &optional name
454
455 ### [Class] place-pattern
456
457 ### [Type] place-pattern
458
459 place-pattern
460
461 ### [Function] place-pattern-name
462
463 place-pattern-name instance
464
465 ### [Function] make-place-pattern
466
467 make-place-pattern name
468
469 ### [Class] constant-pattern
470
471 ### [Type] constant-pattern
472
473 constant-pattern
474
475 ### [Function] constant-pattern-value
476
477 constant-pattern-value instance
478
479 ### [Function] make-constant-pattern
480
481 make-constant-pattern value
482
483 ### [Class] complex-pattern
484
485 ### [Type] complex-pattern
486
487 complex-pattern
488
489 ### [Function] complex-pattern-subpatterns
490
491 complex-pattern-subpatterns instance
492
493 ### [Class] guard-pattern
494
495 ### [Type] guard-pattern
496
497 guard-pattern
498
499 ### [Function] guard-pattern-test-form
500
501 guard-pattern-test-form instance
502
503 ### [Function] guard-pattern-subpattern
504
505 guard-pattern-subpattern pattern
506
507 ### [Function] make-guard-pattern
508
509 make-guard-pattern subpattern test-form &aux (subpatterns (list subpattern))
510
511 ### [Class] not-pattern
512
513 ### [Type] not-pattern
514
515 not-pattern
516
517 ### [Function] not-pattern-subpattern
518
519 not-pattern-subpattern pattern
520
521 ### [Function] make-not-pattern
522
523 make-not-pattern subpattern &aux (subpatterns (list subpattern))
524
525 ### [Class] or-pattern
526
527 ### [Type] or-pattern
528
529 or-pattern
530
531 ### [Function] or-pattern-subpatterns
532
533 or-pattern-subpatterns instance
534
535 ### [Function] make-or-pattern
536
537 make-or-pattern &rest subpatterns
538
539 ### [Class] and-pattern
540
541 ### [Type] and-pattern
542
543 and-pattern
544
545 ### [Function] and-pattern-subpatterns
546
547 and-pattern-subpatterns instance
548
549 ### [Function] make-and-pattern
550
551 make-and-pattern &rest subpatterns
552
553 ### [Class] constructor-pattern
554
555 ### [Type] constructor-pattern
556
557 constructor-pattern
558
559 ### [Function] constructor-pattern-subpatterns
560
561 constructor-pattern-subpatterns instance
562
563 ### [Function] constructor-pattern-arity
564
565 constructor-pattern-arity pattern
566
567 ### [Function] constructor-pattern-destructor-sharable-p
568
569 constructor-pattern-destructor-sharable-p x y
570
571 ### [Function] constructor-pattern-make-destructor
572
573 constructor-pattern-make-destructor pattern var
574
575 ### [Class] cons-pattern
576
577 ### [Type] cons-pattern
578
579 cons-pattern
580
581 ### [Function] cons-pattern-car-pattern
582
583 cons-pattern-car-pattern pattern
584
585 ### [Function] cons-pattern-cdr-pattern
586
587 cons-pattern-cdr-pattern pattern
588
589 ### [Function] make-cons-pattern
590
591 make-cons-pattern car-pattern cdr-pattern &aux (subpatterns
592 (list car-pattern cdr-pattern))
593
594 ### [Class] assoc-pattern
595
596 ### [Type] assoc-pattern
597
598 assoc-pattern
599
600 ### [Function] assoc-pattern-item
601
602 assoc-pattern-item instance
603
604 ### [Function] assoc-pattern-key
605
606 assoc-pattern-key instance
607
608 ### [Function] assoc-pattern-test
609
610 assoc-pattern-test instance
611
612 ### [Function] assoc-pattern-value-pattern
613
614 assoc-pattern-value-pattern pattern
615
616 ### [Function] make-assoc-pattern
617
618 make-assoc-pattern item value-pattern &key (key nil) (test nil) &aux (subpatterns
619 (list
620 value-pattern))
621
622 ### [Class] property-pattern
623
624 ### [Type] property-pattern
625
626 property-pattern
627
628 ### [Function] property-pattern-item
629
630 property-pattern-item instance
631
632 ### [Function] property-pattern-value-pattern
633
634 property-pattern-value-pattern pattern
635
636 ### [Function] make-property-pattern
637
638 make-property-pattern item value-pattern &aux (subpatterns (list value-pattern))
639
640 ### [Class] vector-pattern
641
642 ### [Type] vector-pattern
643
644 vector-pattern
645
646 ### [Function] vector-pattern-subpatterns
647
648 vector-pattern-subpatterns instance
649
650 ### [Function] make-vector-pattern
651
652 make-vector-pattern &rest subpatterns
653
654 ### [Class] simple-vector-pattern
655
656 ### [Type] simple-vector-pattern
657
658 simple-vector-pattern
659
660 ### [Function] simple-vector-pattern-subpatterns
661
662 simple-vector-pattern-subpatterns instance
663
664 ### [Function] make-simple-vector-pattern
665
666 make-simple-vector-pattern &rest subpatterns
667
668 ### [Class] class-pattern
669
670 ### [Type] class-pattern
671
672 class-pattern
673
674 ### [Function] class-pattern-subpatterns
675
676 class-pattern-subpatterns instance
677
678 ### [Function] class-pattern-class-name
679
680 class-pattern-class-name instance
681
682 ### [Function] class-pattern-slot-names
683
684 class-pattern-slot-names instance
685
686 ### [Function] make-class-pattern
687
688 make-class-pattern class-name &rest slot-specs
689
690 ### [Class] structure-pattern
691
692 ### [Type] structure-pattern
693
694 structure-pattern
695
696 ### [Function] structure-pattern-subpatterns
697
698 structure-pattern-subpatterns instance
699
700 ### [Function] structure-pattern-conc-name
701
702 structure-pattern-conc-name instance
703
704 ### [Function] structure-pattern-slot-names
705
706 structure-pattern-slot-names instance
707
708 ### [Function] make-structure-pattern
709
710 make-structure-pattern conc-name &rest slot-specs
711
712 ### [Function] pattern-variables
713
714 pattern-variables pattern
715
716 Returns the set of variables in PATTERN. If PATTERN is not linear,
717 an error will be raised.
718
719 ### [Function] place-pattern-included-p
720
721 place-pattern-included-p pattern
722
723 ### [Function] check-patterns
724
725 check-patterns patterns
726
727 Check if PATTERNS are valid. Otherwise, an error will be raised.
728
729 ### [Function] lift-guard-patterns
730
731 lift-guard-patterns pattern
732
733 ### [Function] pattern-expand-function
734
735 pattern-expand-function name
736
737 ### [Function] pattern-expand-1
738
739 pattern-expand-1 pattern
740
741 ### [Function] pattern-expand
742
743 pattern-expand pattern
744
745 ### [Function] pattern-expand-all
746
747 pattern-expand-all pattern
748
749 ### [Function] parse-pattern
750
751 parse-pattern pattern
752
753 ### [Function] parse-constructor-pattern
754
755 parse-constructor-pattern name &rest args
756
757 ### [Function] unparse-pattern
758
759 unparse-pattern pattern
760
a0e94a1 Documentation.
Tomohiro Matsuyama authored
761 [Package] optima
457d6a0 Documentation.
Tomohiro Matsuyama authored
762 ----------------
763
dea6d2d Add optima.core package
Tomohiro Matsuyama authored
764 ### [Macro] match
457d6a0 Documentation.
Tomohiro Matsuyama authored
765
766 match arg &body clauses
767
a859b3d Documentation.
Tomohiro Matsuyama authored
768 Matches ARG with CLAUSES. CLAUSES is a list of the form of (PATTERN
769 . BODY) where PATTERN is a pattern specifier and BODY is an implicit
11f6e25 Minor edits.
Robert P. Goldman authored
770 progn. If ARG matches some PATTERN, `match` then evaluates
771 the corresponding BODY and returns the evaluated value. If no pattern matches,
772 then returns NIL.
457d6a0 Documentation.
Tomohiro Matsuyama authored
773
5fc9b07 Manual failure.
Tomohiro Matsuyama authored
774 Evaluating a form (FAIL) in the clause body causes the latest pattern
411b822 @m2ym Recover leak of documentation fix.
authored
775 matching to fail. For example,
5fc9b07 Manual failure.
Tomohiro Matsuyama authored
776
777 (match 1
778 (x (if (eql x 1)
779 (fail)
780 x))
781 (_ 'ok))
782
783 returns OK, because the form (FAIL) in the first clause is
784 evaluated.
785
37eeaf5 Fix documentation
Tomohiro Matsuyama authored
786 If BODY starts with the symbols WHEN or UNLESS, then the next form
787 will be used to introduce (FAIL). That is,
788
789 (match list ((list x) when (oddp x) x))
790 (match list ((list x) unless (evenp x) x))
791
792 will be translated to
793
794 (match list ((list x) (if (oddp x) x (fail))))
795 (match list ((list x) (if (evenp x) (fail) x)))
796
5fc9b07 Manual failure.
Tomohiro Matsuyama authored
797 Examples:
798
799 (match 1 (1 1))
800 => 1
801 (match 1 (2 2))
802 => 2
803 (match 1 (x x))
804 => 1
805 (match (list 1 2 3)
806 (list x y z) (+ x y z))
807 => 6
808
dea6d2d Add optima.core package
Tomohiro Matsuyama authored
809 ### [Macro] multiple-value-match
c845586 Added match-values, ematch-values, cmatch-values.
Tomohiro Matsuyama authored
810
ee5e067 Renamed match-values to multiple-value-match.
Tomohiro Matsuyama authored
811 multiple-value-match values-form &body clauses
c845586 Added match-values, ematch-values, cmatch-values.
Tomohiro Matsuyama authored
812
813 Matches the multiple values of VALUES-FORM with CLAUSES. Unlike
3e46aab Added list* pattern.
Tomohiro Matsuyama authored
814 MATCH, CLAUSES have to have the form of (PATTERNS . BODY), where
c845586 Added match-values, ematch-values, cmatch-values.
Tomohiro Matsuyama authored
815 PATTERNS is a list of patterns. The number of values that will be used
3e46aab Added list* pattern.
Tomohiro Matsuyama authored
816 to match is determined by the maximum arity of PATTERNS among CLAUSES.
c845586 Added match-values, ematch-values, cmatch-values.
Tomohiro Matsuyama authored
817
818 Examples:
819
ee5e067 Renamed match-values to multiple-value-match.
Tomohiro Matsuyama authored
820 (multiple-value-match (values 1 2)
c845586 Added match-values, ematch-values, cmatch-values.
Tomohiro Matsuyama authored
821 ((2) 1)
822 ((1 y) y))
823 => 2
824
dea6d2d Add optima.core package
Tomohiro Matsuyama authored
825 ### [Macro] ematch
457d6a0 Documentation.
Tomohiro Matsuyama authored
826
827 ematch arg &body clauses
828
829 Same as MATCH, except MATCH-ERROR will be raised if not matched.
830
dea6d2d Add optima.core package
Tomohiro Matsuyama authored
831 ### [Macro] multiple-value-ematch
c845586 Added match-values, ematch-values, cmatch-values.
Tomohiro Matsuyama authored
832
ee5e067 Renamed match-values to multiple-value-match.
Tomohiro Matsuyama authored
833 multiple-value-ematch values-form &body clauses
c845586 Added match-values, ematch-values, cmatch-values.
Tomohiro Matsuyama authored
834
ee5e067 Renamed match-values to multiple-value-match.
Tomohiro Matsuyama authored
835 Same as MULTIPLE-VALUE-MATCH, except MATCH-ERROR will be raised if
836 not matched.
c845586 Added match-values, ematch-values, cmatch-values.
Tomohiro Matsuyama authored
837
dea6d2d Add optima.core package
Tomohiro Matsuyama authored
838 ### [Macro] cmatch
457d6a0 Documentation.
Tomohiro Matsuyama authored
839
840 cmatch arg &body clauses
841
11f6e25 Minor edits.
Robert P. Goldman authored
842 Same as MATCH, except a continuable MATCH-ERROR will be raised if none of the
843 clauses match.
457d6a0 Documentation.
Tomohiro Matsuyama authored
844
dea6d2d Add optima.core package
Tomohiro Matsuyama authored
845 ### [Macro] multiple-value-cmatch
c845586 Added match-values, ematch-values, cmatch-values.
Tomohiro Matsuyama authored
846
ee5e067 Renamed match-values to multiple-value-match.
Tomohiro Matsuyama authored
847 multiple-value-cmatch values-form &body clauses
c845586 Added match-values, ematch-values, cmatch-values.
Tomohiro Matsuyama authored
848
11f6e25 Minor edits.
Robert P. Goldman authored
849 Same as MULTIPLE-VALUE-MATCH, except a continuable MATCH-ERROR will
850 be raised if none of the clauses match.
c845586 Added match-values, ematch-values, cmatch-values.
Tomohiro Matsuyama authored
851
dea6d2d Add optima.core package
Tomohiro Matsuyama authored
852 ### [Macro] fail
5fc9b07 Manual failure.
Tomohiro Matsuyama authored
853
854 fail
855
411b822 @m2ym Recover leak of documentation fix.
authored
856 Causes the latest pattern matching to fail. After this failure,
857 matching continues at the next pattern.
5fc9b07 Manual failure.
Tomohiro Matsuyama authored
858
dea6d2d Add optima.core package
Tomohiro Matsuyama authored
859 ### [Class] match-error
dfc66e8 Export MATCH-ERROR
Tomohiro Matsuyama authored
860
dea6d2d Add optima.core package
Tomohiro Matsuyama authored
861 ### [Type] match-error
dfc66e8 Export MATCH-ERROR
Tomohiro Matsuyama authored
862
863 match-error
864
dea6d2d Add optima.core package
Tomohiro Matsuyama authored
865 ### [Function] match-error-values
dfc66e8 Export MATCH-ERROR
Tomohiro Matsuyama authored
866
867 match-error-values condition
868
dea6d2d Add optima.core package
Tomohiro Matsuyama authored
869 ### [Function] match-error-patterns
dfc66e8 Export MATCH-ERROR
Tomohiro Matsuyama authored
870
871 match-error-patterns condition
872
dea6d2d Add optima.core package
Tomohiro Matsuyama authored
873 ### [Macro] defpattern
5fc9b07 Manual failure.
Tomohiro Matsuyama authored
874
875 defpattern name lambda-list &body body
876
877 Defines a derived pattern specifier named NAME. This is analogous
878 to DEFTYPE.
879
880 Examples:
881
882 ;; Defines a LIST pattern.
883 (defpattern list (&rest args)
884 (when args
885 `(cons ,(car args) (list ,@(cdr args)))))
886
a319c5b Add OPTIMA.EXTRA package with some useful macros
Tomohiro Matsuyama authored
887 [Package] optima.extra
888 ----------------------
889
ef3ac4f Add optima.ppcre system
Tomohiro Matsuyama authored
890
891 ### [Pattern] alist
892
893 Syntax:
894
895 (alist (KEY . PATTERN)*)
896
897 Expansion:
898
899 (alist (k . p)*) => (and (assoc k p)*)
900
901 Examples:
902
903 (match '((1 . :one) (2 . :two) (3 . :three))
904 ((alist (1 . x) (3 . y)) (list x y)))
905 => (:ONE :THREE)
906
907 ### [Pattern] plist
908
909 Syntax:
910
911 (plist {KEY PATTERN}*)
912
913 Expansion:
914
f11a8b6 Fix documentation of PLIST pattern
Tomohiro Matsuyama authored
915 (plist {k p}*) => (and (property k p)*)
ef3ac4f Add optima.ppcre system
Tomohiro Matsuyama authored
916
917 Examples:
918
919 (match '(:name "John" :age 23)
920 ((plist :name "John" :age age) age))
921 => 23
922
dea6d2d Add optima.core package
Tomohiro Matsuyama authored
923 ### [Macro] if-match
a319c5b Add OPTIMA.EXTRA package with some useful macros
Tomohiro Matsuyama authored
924
925 if-match pattern arg &body (then &optional else)
926
927 Equivalent to (match ARG (PATTERN THEN) (otherwise ELSE)).
928
dea6d2d Add optima.core package
Tomohiro Matsuyama authored
929 ### [Macro] when-match
a319c5b Add OPTIMA.EXTRA package with some useful macros
Tomohiro Matsuyama authored
930
931 when-match pattern arg &body body
932
933 Equivalent to (match ARG (PATTERN BODY...)).
934
dea6d2d Add optima.core package
Tomohiro Matsuyama authored
935 ### [Macro] unless-match
a319c5b Add OPTIMA.EXTRA package with some useful macros
Tomohiro Matsuyama authored
936
937 unless-match pattern arg &body body
938
939 Equivalent to (match ARG (PATTERN) (otherwise BODY...)).
940
dea6d2d Add optima.core package
Tomohiro Matsuyama authored
941 ### [Macro] let-match
a319c5b Add OPTIMA.EXTRA package with some useful macros
Tomohiro Matsuyama authored
942
943 let-match bindings &body body
944
945 Similar to LET, except not only a variable but also a pattern can
946 be used in BINDINGS.
947
dea6d2d Add optima.core package
Tomohiro Matsuyama authored
948 ### [Macro] let-match*
a319c5b Add OPTIMA.EXTRA package with some useful macros
Tomohiro Matsuyama authored
949
950 let-match* bindings &body body
951
952 Similar to LET-MATCH but matches sequentially.
953
dea6d2d Add optima.core package
Tomohiro Matsuyama authored
954 ### [Macro] let-match1
a319c5b Add OPTIMA.EXTRA package with some useful macros
Tomohiro Matsuyama authored
955
956 let-match1 pattern arg &body body
957
958 Equivalent to (let-match ((PATTERN ARG)) BODY...).
959
804d9ee Add lambda-match family
Tomohiro Matsuyama authored
960 ### [Macro] lambda-match
961
962 lambda-match &body clauses
963
964 Equivalent to (lambda (arg) (match arg CLAUSES...)).
965
966 ### [Macro] lambda-ematch
967
968 lambda-ematch &body clauses
969
970 Equivalent to (lambda (arg) (ematch arg CLAUSES...)).
971
972 ### [Macro] lambda-cmatch
973
974 lambda-cmatch &body clauses
975
976 Equivalent to (lambda (arg) (cmatch arg CLAUSES...)).
977
978 ### [Macro] lambda-match1
979
980 lambda-match1 pattern &body body
981
982 Equivalent to (lambda-match (PATTERN BODY...)).
983
984 ### [Macro] lambda-ematch1
985
986 lambda-ematch1 pattern &body body
987
988 Equivalent to (lambda-ematch (PATTERN BODY...)).
989
990 ### [Macro] lambda-cmatch1
991
992 lambda-cmatch1 pattern &body body
993
994 Equivalent to (lambda-cmatch (PATTERN BODY...)).
995
2475a18 Add ASSOC and PASSOC patterns
Tomohiro Matsuyama authored
996 Authors
997 -------
715e07f @naryl non-CL pattern designators are in optima.extra now
naryl authored
998
2475a18 Add ASSOC and PASSOC patterns
Tomohiro Matsuyama authored
999 * Tomohiro Matsuyama
715e07f @naryl non-CL pattern designators are in optima.extra now
naryl authored
1000
2475a18 Add ASSOC and PASSOC patterns
Tomohiro Matsuyama authored
1001 License
1002 -------
715e07f @naryl non-CL pattern designators are in optima.extra now
naryl authored
1003
2475a18 Add ASSOC and PASSOC patterns
Tomohiro Matsuyama authored
1004 LLGPL
715e07f @naryl non-CL pattern designators are in optima.extra now
naryl authored
1005
ef3ac4f Add optima.ppcre system
Tomohiro Matsuyama authored
1006 optima.ppcre - CL-PPCRE support for optima
1007 ==========================================
715e07f @naryl non-CL pattern designators are in optima.extra now
naryl authored
1008
ef3ac4f Add optima.ppcre system
Tomohiro Matsuyama authored
1009 [Package] optima.ppcre
1010 ----------------------
5401384 Add PPCRE pattern as contrib
Tomohiro Matsuyama authored
1011
1012
ef3ac4f Add optima.ppcre system
Tomohiro Matsuyama authored
1013 ### [Pattern] ppcre
5401384 Add PPCRE pattern as contrib
Tomohiro Matsuyama authored
1014
2475a18 Add ASSOC and PASSOC patterns
Tomohiro Matsuyama authored
1015 Syntax:
1016
5401384 Add PPCRE pattern as contrib
Tomohiro Matsuyama authored
1017 (ppcre REGEXP PATTERN*)
1018
1019 Matches REGEXP against the target string. Sub-PATTERNs will be used to
11f6e25 Minor edits.
Robert P. Goldman authored
1020 match the matched groups, if the REGEXP matched.
5401384 Add PPCRE pattern as contrib
Tomohiro Matsuyama authored
1021
1022 Examples:
1023
1024 (match "2012-11-04"
d0e5357 Fix optima.ppcre documentation.
Tomohiro Matsuyama authored
1025 ((ppcre "^(\\d{4})-(\\d{2})-(\\d{2})$" year month day)
5401384 Add PPCRE pattern as contrib
Tomohiro Matsuyama authored
1026 (list year month day)))
1027 => ("2012" "11" "04")
1028
1029 Authors
1030 -------
1031
1032 * Tomohiro Matsuyama
1033
1034 License
1035 -------
1036
1037 LLGPL
Something went wrong with that request. Please try again.