summaryrefslogtreecommitdiffstats
path: root/net/ricketyspace
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2018-05-19 05:13:24 +0000
committerrsiddharth <s@ricketyspace.net>2018-05-19 05:13:24 +0000
commite33cb77079e7573b62dd44be493f4ef2975446d3 (patch)
tree0d99ed367a986bd6a8d98347cf71cafcf8034870 /net/ricketyspace
parentd0dd460e4934adabcdae7665bf79a8d7d4bea656 (diff)
net: Add (net ricketyspace sicp two one).
* net/ricketyspace/sicp/two/one.scm: New file.
Diffstat (limited to 'net/ricketyspace')
-rw-r--r--net/ricketyspace/sicp/two/one.scm22
1 files changed, 22 insertions, 0 deletions
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
+;;;; <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))))