; Can you write your function as a thunk?
; ------------------------------
; The Little Lisper 3rd Edition
; Chapter 9
; Exercise 8
; 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-9-lamdba-ultimate.html
; http://t...content-available-to-author-only...t.com/2010/06/little-lisper.html
; ------------------------------
(defun member? (a lat)
(cond
((null lat) NIL)
((eq a (car lat)) t)
(t
(member? a (cdr lat)))))
(print (member? 'x '(a b c d e f)))
(print (member? 'f '(a b c d e f)))
(defun subset? (lat lat2)
(cond
((null lat) t)
(t
(and (member? (car lat) lat2)
(subset? (cdr lat) lat2)))))
(print (subset? '(a b) '(a c d)))
(print (subset? '(a c) '(a c d)))
(defun intersect? (lat lat2)
(cond
((null lat) t)
(t
(or (member? (car lat) lat2)
(intersect? (cdr lat) lat2)))))
(print (intersect? '(a b) '(a c d)))
(print (intersect? '(a c) '(a c d)))
(defun or-func (or1 or2)
(or (funcall or1)(funcall or2)))
(defun and-func (or1 or2)
(and (funcall or1)(funcall or2)))
(setf (symbol-function 'set-f?)
(lambda (current-function)
(function
(lambda (cond1 cond2)
(funcall current-function cond1 cond2)))))
(print (funcall (set-f? 'or-func) (lambda() (= 1 1)) (lambda() (= 1 2))))
;T
(print (or-func (lambda() (= 1 1)) (lambda() (= 1 2))))
;T
(print (funcall (set-f? 'and-func) (lambda() (= 1 1)) (lambda() (= 1 2))))
;NIL false
(print (and-func (lambda() (= 1 1)) (lambda() (= 1 2))))
(defun intersect-func? (lat lat2)
(cond
((null lat) t)
(t
(or-func (lambda() (member? (car lat) lat2))
(lambda() (intersect-func? (cdr lat) lat2))))))
(print (intersect-func? '(a) '(a)))
; T
(print (intersect-func? '(a b) '(a c d)))
; T
(print (intersect-func? '(a c) '(a c d)))
; T
(defun subset-func? (lat lat2)
(cond
((null lat) t)
(t
(and-func (lambda() (member? (car lat) lat2))
(lambda() (subset-func? (cdr lat) lat2))))))
(print (subset-func? '(a b) '(a c d)))
; NIL false
(print (subset-func? '(a c) '(a c d)))
; T