; Can you abstract these two functions into an accumulator?
; ------------------------------
; The Little Lisper 3rd Edition
; Chapter 9
; Exercise 6
; Common Lisp
; http://t...content-available-to-author-only...r.com/thelittlelisper
; http://t...content-available-to-author-only...t.com/2010/06/little-lisper-chapter-9-lamdba-ultimate.html
; http://t...content-available-to-author-only...t.com/2010/06/little-lisper.html
; ------------------------------
; assume addvec is the text and multivec is the exercise from chapter 5
(defun accum ( func terminator lat)
(cond
((null lat) terminator)
(t (funcall func (car lat)
(accum func terminator (cdr lat))))))
(print (accum '+ 0 '(1 2 3 4 5 6) ))
;21
(print (accum '* 1 '(1 2 3 4 5 6) ))
;720
OyBDYW4geW91IGFic3RyYWN0IHRoZXNlIHR3byBmdW5jdGlvbnMgaW50byBhbiBhY2N1bXVsYXRvcj8KOyAtLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0KOyBUaGUgTGl0dGxlIExpc3BlciAzcmQgRWRpdGlvbgo7IENoYXB0ZXIgOQo7IEV4ZXJjaXNlIDYKOyBDb21tb24gTGlzcAo7IGh0dHA6Ly90Li4uY29udGVudC1hdmFpbGFibGUtdG8tYXV0aG9yLW9ubHkuLi5yLmNvbS90aGVsaXR0bGVsaXNwZXIKOyBodHRwOi8vdC4uLmNvbnRlbnQtYXZhaWxhYmxlLXRvLWF1dGhvci1vbmx5Li4udC5jb20vMjAxMC8wNi9saXR0bGUtbGlzcGVyLWNoYXB0ZXItOS1sYW1kYmEtdWx0aW1hdGUuaHRtbAo7IGh0dHA6Ly90Li4uY29udGVudC1hdmFpbGFibGUtdG8tYXV0aG9yLW9ubHkuLi50LmNvbS8yMDEwLzA2L2xpdHRsZS1saXNwZXIuaHRtbAo7IC0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLQoKOyBhc3N1bWUgYWRkdmVjIGlzIHRoZSB0ZXh0IGFuZCBtdWx0aXZlYyBpcyB0aGUgZXhlcmNpc2UgZnJvbSBjaGFwdGVyIDUKCihkZWZ1biBhY2N1bS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