From adf3bf12d8ae16055f381d06079804068e6c1611 Mon Sep 17 00:00:00 2001 From: Tim Vaughan Date: Sat, 17 Dec 2016 00:07:56 +1300 Subject: [PATCH] Added hacky fixnum division op. Now we can get through at least the first few pages of SICP. --- src/scheme-library.scm | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/scheme-library.scm b/src/scheme-library.scm index fc3c9b9..e8e9245 100644 --- a/src/scheme-library.scm +++ b/src/scheme-library.scm @@ -58,13 +58,15 @@ ; Binary operations +(define (fix:/ x y) ; Non-standard definition while we don't have rationals + (if (fix:= 0 (fix:remainder x y)) + (fix:quotient x y) + (flo:/ (fixnum->flonum x) (fixnum->flonum y)))) + (define (pair+ x y) (promote-dispatch (cons fix:+ flo:+) x y)) (define (pair- x y) (promote-dispatch (cons fix:- flo:-) x y)) (define (pair* x y) (promote-dispatch (cons fix:* flo:*) x y)) -(define (pair/ x y) (promote-dispatch - (cons (lambda 'args - (error "Division unsupported for integers.")) - flo:/) x y)) +(define (pair/ x y) (promote-dispatch (cons fix:/ flo:/) x y)) (define (pair> x y) (promote-dispatch (cons fix:> flo:>) x y)) (define (pair< x y) (promote-dispatch (cons fix:< flo:<) x y)) -- 2.20.1