From e33cb77079e7573b62dd44be493f4ef2975446d3 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Sat, 19 May 2018 05:13:24 +0000 Subject: net: Add (net ricketyspace sicp two one). * net/ricketyspace/sicp/two/one.scm: New file. --- net/ricketyspace/sicp/two/one.scm | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 net/ricketyspace/sicp/two/one.scm (limited to 'net') diff --git a/net/ricketyspace/sicp/two/one.scm b/net/ricketyspace/sicp/two/one.scm new file mode 100644 index 0000000..5d184dc --- /dev/null +++ b/net/ricketyspace/sicp/two/one.scm @@ -0,0 +1,22 @@ +;;;; Under Creative Commons Attribution-ShareAlike 4.0 +;;;; International. See +;;;; . + +(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)))) -- cgit v1.2.3