Skip to content

Instantly share code, notes, and snippets.

@chelseatroy
Last active November 2, 2019 21:15
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/c848db246f46f673c91d0fc0fff2ba04 to your computer and use it in GitHub Desktop.
Save chelseatroy/c848db246f46f673c91d0fc0fff2ba04 to your computer and use it in GitHub Desktop.
Data Represented as a Different Procedure
; 2.5
(define expt (** a b))
(define (2.5-cons a b)
(* (expt 2 a) (expt 3 b))
)
(define (2.5-car product)
(if (= 0 (remainder product 2))
(+ 1 (2.5-car (/ product 2)))
0)
)
(define (2.5-cdr product)
(if (= 0 (remainder product 3))
(+ 1 (2.5-cdr (/ product 3)))
0)
)
(define example (2.5-cons 5 7)) ; 69984
(2.5-car example) ; 5
(2.5-cdr example) ; 7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment