fork download
  1. ; Adding the nested numbers
  2. ; ------------------------------
  3. ; The Little Lisper 3rd Edition
  4. ; Chapter 6
  5. ; Exercise 6
  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. (defun addvec (vec)
  19. (cond
  20. ((null vec) 0)
  21. (t (+ (car vec)(addvec (cdr vec))))))
  22.  
  23. (print (addvec '(1 2 3)))
  24. ;6
  25.  
  26. (defun notatom (lat)
  27. (not (atom lat)))
  28.  
  29. (defun list+ (vec)
  30. (cond
  31. ((null vec) 0)
  32. ((notatom (car vec))
  33. (+ (list+ (car vec))
  34. (list+ (cdr vec))))
  35. (t (+ (car vec)(list+ (cdr vec))))))
  36.  
  37. (print (list+ '(1 2 3)))
  38. ;6
  39. (print (list+ '(1 (2 (3)))))
  40. ;6
  41.  
Success #stdin #stdout 0.02s 10544KB
stdin
Standard input is empty
stdout
6 
6 
6