fork(1) download
  1. ; Recursive version of accumulate
  2. (define (accumulate a b combiner null-value term next)
  3. (if (> a b)
  4. null-value
  5. (combiner (term a)
  6. (accumulate (next a) b combiner null-value term next))))
  7.  
  8. ; Iterative version of accumulate
  9. (define (accumulate-iter a b combiner null-value term next)
  10. (define (iter a result)
  11. (if (> a b)
  12. result
  13. (iter (next a) (combiner result
  14. (term a)))))
  15. (iter a null-value))
  16.  
  17. ; implementation of sum func using accumulate
  18. ; (recursive accumulate)
  19. (define (sum a b)
  20. (accumulate a b + 0 (lambda (x) (x))
  21. (lambda (x) (+ x 1))))
  22.  
  23. ; implementation of product func using accumulate
  24. ; (iterative accumulate)
  25. (define (product a b)
  26. (accumulate-iter a b * 1 (lambda (x) (x))
  27. (lambda (x) (+ x 1))))
  28.  
  29. ; sum all naturals in [1..10] (recursive accumulate)
  30. (sum 1 10)
  31. (newline)
  32.  
  33. ; multiply all naturals in [1..10] (recursive accumulate)
  34. (product 1 10)
  35. (newline)
  36.  
Runtime error #stdin #stdout #stderr 0.06s 10208KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Backtrace:
In ice-9/boot-9.scm:
 157: 10 [catch #t #<catch-closure 84e1bd0> ...]
In unknown file:
   ?: 9 [apply-smob/1 #<catch-closure 84e1bd0>]
In ice-9/boot-9.scm:
  63: 8 [call-with-prompt prompt0 ...]
In ice-9/eval.scm:
 432: 7 [eval # #]
In ice-9/boot-9.scm:
2401: 6 [save-module-excursion #<procedure 84f0cc0 at ice-9/boot-9.scm:4045:3 ()>]
4052: 5 [#<procedure 84f0cc0 at ice-9/boot-9.scm:4045:3 ()>]
1724: 4 [%start-stack load-stack ...]
1729: 3 [#<procedure 84f6738 ()>]
In unknown file:
   ?: 2 [primitive-load "/home/WshfsT/prog.scm"]
In ice-9/eval.scm:
 387: 1 [eval # #]
In unknown file:
   ?: 0 [1]

ERROR: In procedure 1:
ERROR: Wrong type to apply: 1