- ; Evaluate your expression in your DSL 
- ; ------------------------------ 
- ; The Little Lisper 3rd Edition 
- ; Chapter 7 
- ; Exercise 9 
- ; 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 lookup (a lat) 
-   (cond 
-    ((null a) NIL) 
-    ((null lat) NIL) 
-    ((eq a (car (car lat))) 
-     (cdr (car lat))) 
-    (t  
-     (lookup a (cdr lat))))) 
-   
- (defun operator (aexp_) 
-   (car aexp_)) 
-   
- (defun 1st-sub-expr (aexp_) 
-   (car (cdr aexp_))) 
-   
- (defun 2nd-sub-expr (aexp_) 
-   (car (cdr (cdr aexp_)))) 
-   
- (defun Mlexp (lexp_ alist_) 
-   (cond 
-    ((null lexp_) NIL) 
-    ((null alist_) NIL) 
-    ((atom lexp_) 
-     (cond 
-      ;((eq lexp_ 't) t) 
-      ((= 1 (car(lookup lexp_ alist_))) t) 
-      (t NIL))) 
-    ((eq (operator lexp_) 'AND) 
-     (cond 
-     ((and 
-      (Mlexp (1st-sub-expr lexp_) alist_) 
-      (Mlexp (2nd-sub-expr lexp_) alist_)) 
-      't) 
-      (t NIL))) 
-    ((eq (operator lexp_) 'OR) 
-     (cond 
-     ((or 
-      (Mlexp (1st-sub-expr lexp_) alist_) 
-      (Mlexp (2nd-sub-expr lexp_) alist_)) 
-      't) 
-      (t NIL))) 
-     ((eq (operator lexp_) 'NOT) 
-      (cond 
-     ((not 
-      (Mlexp (1st-sub-expr lexp_) alist_)) 
-       't) 
-      (t NIL))) 
-    (t NIL))) 
-   
- (setf lexp1 '(AND (OR x y) y)) 
-   
- (print (Mlexp lexp1 '((x 1)(y 0)(z 0)))) 
- ;NIL false 
-   
- (print (Mlexp lexp2 '((y 0)(u 0)(v 1)))) 
- ;T  
-   
- (print (Mlexp lexp4 '((x 1)(y 0)(z 0)))) 
- ; NIL false 
-