fork download
  1. ; Are these equal? Does it break the law?
  2. ; ------------------------------
  3. ; The Little Lisper 3rd Edition
  4. ; Chapter 5
  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-5-multichapter.html
  9. ; http://t...content-available-to-author-only...t.com/2010/06/little-lisper.html
  10. ; ------------------------------
  11. (setf x 'comma)
  12. (setf y 'dot)
  13. (setf a 'kiwis)
  14. (setf b 'plums)
  15. (setf lat1 '(bananas kiwis))
  16. (setf lat2 '(peaches apples bananas))
  17. (setf lat3 '(kiwis pears plums bananas cherries))
  18. (setf lat4 '(kiwis mangoes kiwis guavas kiwis))
  19. (setf l1 '((curry) () (chicken) ()))
  20. (setf l2 '((peaches) (and cream)))
  21. (setf l4 '())
  22. ; ------------------------------
  23.  
  24. ; Because the changing argument should be tested in the terminating condition - and in this case it is not
  25. ; In this case the other argument is tested as the terminating condition - which then triggers a test
  26. ; of the recurring agument
  27.  
  28. (defun zero (n)
  29. (= 0 n))
  30.  
  31. (defun sub1 (n)
  32. (- n 1))
  33.  
  34. (defun =_ (n m)
  35. (cond
  36. ((zero n) (zero m))
  37. (t (= n (sub1 m)))))
  38.  
  39. (print (=_ 1 2))
  40.  
  41. ; In the default implementation - this implementation doesn't actually work - we assume they meant this:
  42. (defun =_ (n m)
  43. (cond
  44. ((zero n) (zero m))
  45. (t (= m (sub1 n)))))
  46.  
  47. (print (=_ 1 2))
  48.  
  49. ;In this case - the recurring argument is not directly tested for a null condition, but it is triggered when
  50. ;recurring as the arguments are flipped around - in which case it is in the spirit of the the sixth commandment
  51.  
  52.  
Success #stdin #stdout 0.01s 10592KB
stdin
Standard input is empty
stdout
T 
NIL