fork download
  1. ; Can you abstract these two functions into an accumulator?
  2. ; ------------------------------
  3. ; The Little Lisper 3rd Edition
  4. ; Chapter 9
  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-9-lamdba-ultimate.html
  9. ; http://t...content-available-to-author-only...t.com/2010/06/little-lisper.html
  10. ; ------------------------------
  11.  
  12. ; assume addvec is the text and multivec is the exercise from chapter 5
  13.  
  14. (defun accum ( func terminator lat)
  15. (cond
  16. ((null lat) terminator)
  17. (t (funcall func (car lat)
  18. (accum func terminator (cdr lat))))))
  19.  
  20. (print (accum '+ 0 '(1 2 3 4 5 6) ))
  21. ;21
  22.  
  23. (print (accum '* 1 '(1 2 3 4 5 6) ))
  24. ;720
  25.  
Success #stdin #stdout 0.01s 10584KB
stdin
Standard input is empty
stdout
21 
720