fork download
  1. ; Expression evals - Is your relation of pairs prepped?
  2. ; ------------------------------
  3. ; The Little Lisper 3rd Edition
  4. ; Chapter 8
  5. ; Exercise 7
  6. ; Common Lisp
  7. ; http://t...content-available-to-author-only...r.com/thelittlelisper
  8. ; http://t...content-available-to-author-only...t.com/2010/06/little-lisper-chapter-8-friends-and.html
  9. ; http://t...content-available-to-author-only...t.com/2010/06/little-lisper.html
  10. ; ------------------------------
  11. (setf r1 '((a b)(a a)(b b)))
  12. (setf r2 '((c c)))
  13. (setf r3 '((a c)(b c)))
  14. (setf r4 '((a b)(b a)))
  15. (setf f1 '((a 1)(b 2)(c 2)(d 1)))
  16. (setf f2 '())
  17. (setf f3 '((a 2)(b 1)))
  18. (setf f4 '((1 $)(3 *)))
  19. (setf d1 '(a b))
  20. (setf d2 '(c d))
  21. (setf x 'a)
  22. ; ------------------------------
  23.  
  24. (defun lat? (l)
  25. (cond
  26. ((null l) t)
  27. ((atom (car l)) (lat? (cdr l)))
  28. (t nil)))
  29.  
  30. (defun build (a b)
  31. (cons a (cons b '())))
  32.  
  33. (defun rin (x set)
  34. (cond
  35. ((null x) NIL)
  36. ((null set) '())
  37. ((lat? set)
  38. (cons (build x (car set))
  39. (rin x (cdr set))))
  40. (t NIL)))
  41.  
  42. (print (rin 'a d1))
  43. ;((A A) (A B))
  44. ;note typo in notes - said x when they meant 'a
  45.  
  46. (print (rin 'a d2))
  47. ;((A C) (A D))
  48. ;note typo in notes - said x when they meant 'a
  49.  
  50. (print (rin 'a f2))
  51. ;NIL no answer
  52.  
  53.  
Success #stdin #stdout 0s 10592KB
stdin
Standard input is empty
stdout
((A A) (A B)) 
((A C) (A D)) 
NIL