Skip to content

Instantly share code, notes, and snippets.

@TakashiNakagawa
Created January 3, 2014 03:31
Show Gist options
  • Save TakashiNakagawa/8232213 to your computer and use it in GitHub Desktop.
Save TakashiNakagawa/8232213 to your computer and use it in GitHub Desktop.
(define (sum term a next b)
(if (> a b)
0
(+ (term a)
(sum term (next a) next b))))
; (define (pi-sum a b)
; (define (pi-term x)
; (/ 1.0 (* x (+ x 2))))
; (define (pi-next x)
; (+ x 4))
; (sum pi-term a pi-next b))
(define (pi-sum a b)
(sum (lambda (x) (/ 1.0 (* x (+ x 2))))
a
(lambda (x) (+ x 4))
b))
(print (pi-sum 5 10))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment