Skip to content

Instantly share code, notes, and snippets.

@chelseatroy
Last active November 2, 2019 17:40
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/a8070a5cec95d20f3550334d0981fab6 to your computer and use it in GitHub Desktop.
Save chelseatroy/a8070a5cec95d20f3550334d0981fab6 to your computer and use it in GitHub Desktop.
Composing Procedures
; 1.41
(define (double f)
(lambda (x) (f(f x))))
(define (add-2-to x) (+ 2 x))
(define (inc x) (+ 1 x))
(define (square x) (* x x))
((double add-2-to) 3)
(((double (double double)) inc) 5) ;---> 21 WHY IS THIS 16 TIMES AND NOT 8 TIMES?
; 1.42
(define (compose f g)
(lambda (x) (f (g x))))
((compose add-2-to inc) 4) ;-----------> 7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment