Skip to content

Instantly share code, notes, and snippets.

@chelseatroy
Created November 2, 2019 17:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chelseatroy/9b6dfec1a9a1461f8ff24d67c901181d to your computer and use it in GitHub Desktop.
Save chelseatroy/9b6dfec1a9a1461f8ff24d67c901181d to your computer and use it in GitHub Desktop.
Composing More Procedures
; 1.43
(define (repeated operation n)
(define (operation-iter iterator composed-function)
(if (= iterator 1)
(lambda(x) (composed-function x))
(operation-iter (- iterator 1) (compose operation composed-function))
))
(operation-iter n operation)
)
((repeated square 2) 5) ;-----------> 625
; 1.44
(define (smooth f)
(lambda (x dx) (/ (+ (f (- x dx)) (f x) (f (+ x dx))) 3))
)
((smooth square) 0 4) ;-----------> 10 & 3/4
(repeated ((smooth square) 0 4) 5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment