-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREWRITE.LSP
41 lines (31 loc) · 1 KB
/
REWRITE.LSP
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
; From LISP Second Edition, page 348 (Solution 4-24).
(defun rewrite (l)
(cond ((atom l) l)
((eq (car l) 'nand)
(list 'nand
(rewrite (cadr l))
(rewrite (car (cddr l)))
)
)
((eq (car l) 'not)
(rewrite (list 'nand (cadr l) t))
)
((eq (car l) 'and)
(rewrite (list 'not
(list 'nand (cadr l) (car (cddr l)))))
)
((eq (car l) 'or)
(rewrite (list 'nand
(list 'not (cadr l))
(list 'not (car (cddr l)))))
)
((eq (car l) 'xor)
(rewrite (list 'and
(list 'or (cadr l) (car (cddr l)))
(list 'or
(list 'not (cadr l))
(list 'not (car (cddr l))))))
)
(t (list 'error l))
)
)