; In your DSL check you have values for your expressions
; ------------------------------
; The Little Lisper 3rd Edition
; Chapter 7
; Exercise 7
; Common Lisp
; http://t...content-available-to-author-only...r.com/thelittlelisper
; http://t...content-available-to-author-only...t.com/2010/06/little-lisper-chapter-7-shadows.html
; http://t...content-available-to-author-only...t.com/2010/06/little-lisper.html
; ------------------------------
(setf l1 '())
(setf l2 '(3 + (66 6)))
(setf aexp4 5)
; ------------------------------
(setf lexp1 '(AND (OR x y) y))
(setf lexp2 '(AND (NOT y)(OR u v)))
(setf lexp3 '(OR x y))
(setf lexp4 'z)
(defun notatom (lat)
(not (atom lat)))
(defun add1 (n)
(cond
((null n) '())
((+ n 1))))
(add1 1)
;2
(defun occurNa (a1 lat)
(cond
((null lat) 0)
((null a1) 0)
(t (cond
((eq (car lat) a1)
(add1 (occurNa a1 (cdr lat))))
(t (occurNa a1 (cdr lat)))))))
(print (occurNa 'c (list 'a 'b 'c)))
;1
(setf lat2 '(peaches apples bananas))
(print (occurNa 'bananas lat2))
;1
(defun occurN (alat lat)
(cond
((null alat) 0)
((null lat) 0)
(t (+ (occurNa (car alat) lat)
(occurN (cdr alat) lat)))))
(print (occurN (list 'bananas) (list 'bananas 'peaches 'bananas)))
(defun occur* (a lat)
(cond
((null lat) NIL)
((notatom (car lat))
(or
(occur* a (car lat))
(occur* a (cdr lat))))
((eq a (car lat) ) t)
(t (occur* a (cdr lat)))))
(print (occur* 'bananas '(bananas peaches)))
;T
(print (occur* 'bananas '((bananas) peaches)))
;T
(print (occur* 'kiwis '(bananas peaches)))
;NIL (false)
(defun 1st-sub-expr (aexp_)
(car (cdr aexp_)))
(print (1st-sub-expr '(+ 1 2)))
;1
(defun 2nd-sub-expr (aexp_)
(car (cdr (cdr aexp_))))
(print (2nd-sub-expr '(+ 1 2)))
;2
(defun operator (aexp_)
(car aexp_))
(print (operator '(NOT x)))
; NOT
(defun covered? (lexp_ lat)
(cond
((null lexp_) NIL)
;((not (lexp? lexp_)) NIL)
((atom lexp_)
(occur* lexp_ lat))
(t (cond
((eq (operator lexp_) 'NOT)
(covered? (1st-sub-expr lexp_) lat))
(t
(and
(covered? (1st-sub-expr lexp_) lat)
(covered? (2nd-sub-expr lexp_) lat)))))))
(print (covered? lexp1 '(x y z u)))
;T
(print (covered? lexp2 '(x y z u)))
;NIL (false)
(print (covered? lexp4 '(x y z u)))
;T
(print (covered? '(NOT x) '(x)))
;T
(print (covered? '(NOT x) '(x y)))
;T
(print (covered? '(AND x y) '(x y)))
;T
(print (occur* 'y '(x y)))
;T
;(setf lexp1 '(AND (OR x y) y))
(print (covered? '(OR x y) '(x y z u)))
(print (occur* 'x '(x y z u)))
(print (covered? 'y '(x y z u)) )