-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexamples.lisp
51 lines (41 loc) · 1.28 KB
/
examples.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
(in-package :conformist-examples)
(defun skip-one (data index)
(declare (ignore data))
(1+ index))
(defun skip-symbols (data index)
(format t "index: ~a~%" index)
(let ((elm (elt data index)))
(loop while (< index (length data)) do
(unless (symbolp elm)
(return-from skip-symbols index))
(setf elm (elt data index))
(incf index)))
(format t "skip: ~a~%" (1- index))
(1- index))
(defun add-placeholders ()
(map nil #'define-placeholder
(list :symbol :list :symbols)
(list #'symbolp #'listp #'symbolp)
(list #'skip-one #'skip-one #'skip-symbols)))
(defun remove-placeholders ()
(maphash (lambda (key value)
(declare (ignore value))
(remhash key *placeholders*))
*placeholders*))
(defun test1 ()
(values
;; :list placeholder describes list
(matchp '(:list) '((1 2 3)))
;; :symbol placeholder describes one symbol
(matchp '(:symbol) '(a))
;; placeholders may be nested
(matchp '(:symbol (:symbol :list)) '(a (b (c d))))
;; you can mix placeholders and values
(matchp '(a :symbol (b :list c)) '(a / (b (1 2 3) c)))))
;; :symbols placeholder describes one or more symbols
(defun test2 ()
(matchp '(a :symbols) '(a b c d)))
(defun make-tests ()
(add-placeholders)
(test1)
)