Skip to content

Instantly share code, notes, and snippets.

@yakreved
Created August 13, 2013 07:16
Show Gist options
  • Save yakreved/6218611 to your computer and use it in GitHub Desktop.
Save yakreved/6218611 to your computer and use it in GitHub Desktop.
sicp 2.1
(define (make-rat n d)
(if (> d 0)
(cons n d) (cons (* -1 n) (* -1 d))
))
(define (numer x) (car x))
(define (denom x) (cdr x))
(define (mul-rat x y)
(make-rat
(* (numer x) (numer y))
(* (denom x) (denom y))))
(define x (make-rat 1 -2))
(define y (make-rat 1 2))
(mul-rat x y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment