… | |
… | |
31 | ; Utilities for math. Notice that inexact->exact is primitive, |
31 | ; Utilities for math. Notice that inexact->exact is primitive, |
32 | ; but exact->inexact is not. |
32 | ; but exact->inexact is not. |
33 | (define exact? integer?) |
33 | (define exact? integer?) |
34 | (define exact-integer? integer?) |
34 | (define exact-integer? integer?) |
35 | (define (inexact? x) (and (real? x) (not (integer? x)))) |
35 | (define (inexact? x) (and (real? x) (not (integer? x)))) |
|
|
36 | (define (exact->inexact n) (* n 1.0)) |
|
|
37 | (define exact inexact->exact) |
|
|
38 | (define inexact exact->inexact) |
36 | (define (even? n) (= (remainder n 2) 0)) |
39 | (define (even? n) (= (remainder n 2) 0)) |
37 | (define (odd? n) (not (= (remainder n 2) 0))) |
40 | (define (odd? n) (not (= (remainder n 2) 0))) |
38 | (define (zero? n) (= n 0)) |
41 | (define (zero? n) (= n 0)) |
39 | (define (positive? n) (> n 0)) |
42 | (define (positive? n) (> n 0)) |
40 | (define (negative? n) (< n 0)) |
43 | (define (negative? n) (< n 0)) |
41 | (define complex? number?) |
44 | (define complex? number?) |
42 | (define rational? real?) |
45 | (define rational? real?) |
43 | (define (abs n) (if (>= n 0) n (- n))) |
46 | (define (abs n) (if (>= n 0) n (- n))) |
44 | (define (exact->inexact n) (* n 1.0)) |
|
|
45 | (define (<> n1 n2) (not (= n1 n2))) |
47 | (define (<> n1 n2) (not (= n1 n2))) |
46 | (define (square n) (* n n)) |
48 | (define (square n) (* n n)) |
47 | ;; missing: numerator/denominator/rationalize |
49 | ;; missing: numerator denominator rationalize exact-integer-sqrt |
48 | |
50 | |
49 | ; min and max must return inexact if any arg is inexact |
51 | ; min and max must return inexact if any arg is inexact |
50 | (define (max . lst) |
52 | (define (max . lst) |
51 | (foldr (lambda (a b) |
53 | (foldr (lambda (a b) |
52 | (if (> a b) |
54 | (if (> a b) |
… | |
… | |
173 | (define (string-ci>? a b) (string-cmp? char-ci-cmp? > a b)) |
175 | (define (string-ci>? a b) (string-cmp? char-ci-cmp? > a b)) |
174 | (define (string-ci<=? a b) (string-cmp? char-ci-cmp? <= a b)) |
176 | (define (string-ci<=? a b) (string-cmp? char-ci-cmp? <= a b)) |
175 | (define (string-ci>=? a b) (string-cmp? char-ci-cmp? >= a b)) |
177 | (define (string-ci>=? a b) (string-cmp? char-ci-cmp? >= a b)) |
176 | |
178 | |
177 | (define (list . x) x) |
179 | (define (list . x) x) |
|
|
180 | |
|
|
181 | (define (make-list k . fill) (vector->list (vector k (car fill)))) |
178 | |
182 | |
179 | (define (foldr f x lst) |
183 | (define (foldr f x lst) |
180 | (if (null? lst) |
184 | (if (null? lst) |
181 | x |
185 | x |
182 | (foldr f (f x (car lst)) (cdr lst)))) |
186 | (foldr f (f x (car lst)) (cdr lst)))) |