Skip to content

Instantly share code, notes, and snippets.

@chelseatroy
Created October 30, 2019 14:58
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/36bd9888e45ec1afe5a1559fb12cfb18 to your computer and use it in GitHub Desktop.
Save chelseatroy/36bd9888e45ec1afe5a1559fb12cfb18 to your computer and use it in GitHub Desktop.
Representing Primitives as Procedures
; 2.6: Representing a primitive (numbers) as procedures
(define zero (lambda (f) (lambda (x) x)))
(define (add-1 n)
(lambda (f) (lambda (x) (f ((n f) x)))))
(define (inc x) (+ 1 x))
(define one (lambda (f x) (f x)))
(define two (lambda (f x) (f (f x))))
(define three (lambda (f x) (f (f (f x)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment