From: Tim Vaughan Date: Fri, 16 Dec 2016 11:07:56 +0000 (+1300) Subject: Added hacky fixnum division op. X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?p=scheme.forth.jl.git;a=commitdiff_plain;h=adf3bf12d8ae16055f381d06079804068e6c1611 Added hacky fixnum division op. Now we can get through at least the first few pages of SICP. --- 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))