sicp

sicp sandbox.
git clone git://git.ricketyspace.net/sicp.git
Log | Files | Refs

commit e33cb77079e7573b62dd44be493f4ef2975446d3
parent d0dd460e4934adabcdae7665bf79a8d7d4bea656
Author: rsiddharth <s@ricketyspace.net>
Date:   Sat, 19 May 2018 05:13:24 +0000

net: Add (net ricketyspace sicp two one).

* net/ricketyspace/sicp/two/one.scm: New file.

Diffstat:
net/ricketyspace/sicp/two/one.scm | 22++++++++++++++++++++++
1 file changed, 22 insertions(+), 0 deletions(-)

diff --git a/net/ricketyspace/sicp/two/one.scm b/net/ricketyspace/sicp/two/one.scm @@ -0,0 +1,22 @@ +;;;; Under Creative Commons Attribution-ShareAlike 4.0 +;;;; International. See +;;;; <https://creativecommons.org/licenses/by-sa/4.0/>. + +(define-module (net ricketyspace sicp two one) + #:export (make-rat)) + +(define (gcd a b) + (if (= b 0) + a + (gcd b (remainder a b)))) + +(define (make-numer n neg?) + (if neg? (* -1 (abs n)) + (abs n))) +(define (make-denom d) (abs d)) + +(define (make-rat n d) + (let ((g (abs (gcd n d))) + (neg? (< (* n d) 0))) + (cons (/ (make-numer n neg?) g) + (/ (make-denom d) g))))