Last active
August 29, 2015 13:56
-
-
Save parallelepiped/8951362 to your computer and use it in GitHub Desktop.
SICP ex. 1.31
This file contains 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
;helpers | |
(define (identity x) x) | |
(define (plus1 x) (+ 1 x)) | |
; recursive | |
(define (product term a next b) | |
(if (> a b) | |
1 | |
(* (term a) | |
(product term (next a) next b)))) | |
(display (product identity 3 plus1 6)) ; 360 | |
(newline) | |
; iterator | |
(define (product-i term a next b) | |
(define (prod-iter a current_prod) | |
(if (> a b) | |
current_prod | |
(prod-iter (next a) (* current_prod (term a))))) | |
(prod-iter a 1)) | |
(display (product-i identity 3 plus1 6)) ; 360 | |
(newline) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment