fork(1) download
  1. ; What does this function g* do?
  2. ; ------------------------------
  3. ; The Little Lisper 3rd Edition
  4. ; Chapter 6
  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-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 g* (lvec acc)
  20. (cond
  21. ((null lvec) acc)
  22. ((atom (car lvec))
  23. (g* (cdr lvec)(+ (car lvec) acc)))
  24. (t (g* (car lvec)(g* (cdr lvec) acc)))))
  25.  
  26. (print (g* '(1 (2 (3))) 0))
  27. ;6
  28. 'This takes a list of numbers and adds them into the accumulator (acc)
  29.  
  30.  
Success #stdin #stdout 0.03s 10784KB
stdin
Standard input is empty
stdout
6