Last active
December 31, 2015 19:39
-
-
Save toctan/8034749 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (define (sum-int a b) | |
| (if (> a b) | |
| 0 | |
| (+ a | |
| (sum-int (1+ a) b)))) | |
| (define (sum-sq a b) | |
| (if (> a b) | |
| 0 | |
| (+ (square a) | |
| (sum-sq (1+ a) b)))) | |
| (define (sum-pi a b) | |
| (if (> a b) | |
| 0 | |
| (+ (/ 1 (* a (+ a 2))) | |
| (sum-pi (+ a 4) b)))) | |
| ;; Duplication!! | |
| ;; Abstract with procedure as first class citizen | |
| (define (sum term a next b) | |
| (if (> a b) | |
| 0 | |
| (+ (term a) | |
| (sum term (next a) next b)))) | |
| (define (sum-int a b) | |
| (sum (lambda(i) i) a 1+ b)) | |
| (define (sum-sq a b) | |
| (sum square a 1+ b)) | |
| (define (sum-pi a b) | |
| (sum (lambda(i) (/ 1 (* i (+ i 4)))) | |
| a | |
| (lambda(i) (+ i 4)) | |
| b)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment