; Expression evals - Is your relation of pairs prepped?
; ------------------------------
; The Little Lisper 3rd Edition
; Chapter 8
; 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-8-friends-and.html
; http://t...content-available-to-author-only...t.com/2010/06/little-lisper.html
; ------------------------------
(setf r1 '((a b)(a a)(b b)))
(setf r2 '((c c)))
(setf r3 '((a c)(b c)))
(setf r4 '((a b)(b a)))
(setf f1 '((a 1)(b 2)(c 2)(d 1)))
(setf f2 '())
(setf f3 '((a 2)(b 1)))
(setf f4 '((1 $)(3 *)))
(setf d1 '(a b))
(setf d2 '(c d))
(setf x 'a)
; ------------------------------
(defun lat? (l)
(cond
((null l) t)
((atom (car l)) (lat? (cdr l)))
(t nil)))
(defun build (a b)
(cons a (cons b '())))
(defun rin (x set)
(cond
((null x) NIL)
((null set) '())
((lat? set)
(cons (build x (car set))
(rin x (cdr set))))
(t NIL)))
(print (rin 'a d1))
;((A A) (A B))
;note typo in notes - said x when they meant 'a
(print (rin 'a d2))
;((A C) (A D))
;note typo in notes - said x when they meant 'a
(print (rin 'a f2))
;NIL no answer
OyBFeHByZXNzaW9uIGV2YWxzIC0gSXMgeW91ciByZWxhdGlvbiBvZiBwYWlycyBwcmVwcGVkPwo7IC0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLQo7IFRoZSBMaXR0bGUgTGlzcGVyIDNyZCBFZGl0aW9uCjsgQ2hhcHRlciA4CjsgRXhlcmNpc2UgNwo7IENvbW1vbiBMaXNwCjsgaHR0cDovL3QuLi5jb250ZW50LWF2YWlsYWJsZS10by1hdXRob3Itb25seS4uLnIuY29tL3RoZWxpdHRsZWxpc3Blcgo7IGh0dHA6Ly90Li4uY29udGVudC1hdmFpbGFibGUtdG8tYXV0aG9yLW9ubHkuLi50LmNvbS8yMDEwLzA2L2xpdHRsZS1saXNwZXItY2hhcHRlci04LWZyaWVuZHMtYW5kLmh0bWwKOy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