learning-sicp

My embarrassing half assed SICP run.
git clone https://kaka.farm/~git/learning-sicp
Log | Files | Refs

exercise-30.scm (642B)


      1 (define-library (sicp solutions chapter-1 exercise-30)
      2   (import (scheme base))
      3   (export
      4    linear-recursive-sum
      5    iterative-sum
      6    )
      7 
      8   (begin
      9     (define (linear-recursive-sum term a next b)
     10       (if (> a b)
     11           0
     12           (+ (term a)
     13              (linear-recursive-sum term
     14                                    (next a)
     15                                    next
     16                                    b))))
     17 
     18     (define (iterative-sum term a next b)
     19       (define (iter a result)
     20         (if (> a b)
     21             result
     22             (iter (next a)
     23                   (+ (term a)
     24                      result)))
     25         )
     26       (iter a 0))))