fork download
  1. (define (accumulate a b combiner null-value term next)
  2. (if (> a b)
  3. null-value
  4. (combiner (term a)
  5. (accumulate (next a) b combiner null-value term next))))
  6.  
  7. (define (accumulate-iter a b combiner null-value term next)
  8. (define (iter a result)
  9. (if (> a b)
  10. result
  11. (iter (next a) (combiner result
  12. (term a)))))
  13. (iter a null-value))
  14.  
  15. (define (sum a b term next)
  16. (accumulate a b + 0 term next))
  17.  
  18. (define (product a b term next)
  19. (accumulate a b * 1 term next))
  20.  
  21. (define (sum-iter a b term next)
  22. (accumulate-iter a b + 0 term next))
  23.  
  24. (define (product-iter a b term next)
  25. (accumulate-iter a b * 1 term next))
  26.  
  27. (define (identity n) n)
  28.  
  29. (define (inc n) (+ n 1))
  30.  
  31.  
  32.  
  33. (display (sum 1 10 identity inc))
  34. (newline)
  35. (display (sum-iter 1 10 identity inc))
  36. (newline)
  37.  
  38. (display (product 1 10 identity inc))
  39. (newline)
  40. (display (product-iter 1 10 identity inc))
  41. (newline)
Success #stdin #stdout 0.03s 8656KB
stdin
Standard input is empty
stdout
55
55
3628800
3628800