fork download
  1. ; Can we accumulate the (nested) potatoes in this dish?
  2. ; ------------------------------
  3. ; The Little Lisper 3rd Edition
  4. ; Chapter 6
  5. ; Exercise 10
  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-6-oh-my-gawd-its.html
  9. ; http://t...content-available-to-author-only...t.com/2010/06/little-lisper.html
  10. ; ------------------------------
  11. (setf l1 '((fried potatoes)(baked (fried)) tomatoes))
  12. (setf l2 '(((chili) chili (chili))))
  13. (setf l3 '())
  14. (setf lat1 '(chili and hot))
  15. (setf lat2 '(baked fried))
  16. (setf a 'fried)
  17. ; ------------------------------
  18.  
  19. (defun add1 (a)
  20. (+ 1 a))
  21.  
  22. (defun occur* (a lat acc)
  23. (cond
  24. ((null lat) acc)
  25. ((not(atom (car lat)))
  26. (occur* a (cdr lat) (occur* a (car lat) acc)))
  27. (t (cond
  28. ((eq (car lat) a)
  29. (occur* a (cdr lat) (add1 acc)))
  30. (t (occur* a (cdr lat) acc))))))
  31.  
  32. (print (occur* 'a '(a b c d c (b a)) 0))
  33. ;2
  34.  
  35.  
Success #stdin #stdout 0.02s 10544KB
stdin
Standard input is empty
stdout
2