ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/microscheme/init.scm
(Generate patch)

Comparing microscheme/init.scm (file contents):
Revision 1.15 by root, Tue Dec 1 02:21:49 2015 UTC vs.
Revision 1.16 by root, Tue Dec 1 02:29:47 2015 UTC

29 (apply (lambda ,(cdadr dform) ,@(cddr dform)) (cdr ,form)))))) 29 (apply (lambda ,(cdadr dform) ,@(cddr dform)) (cdr ,form))))))
30 30
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 (inexact? x) (and (real? x) (not (integer? x)))) 35(define (inexact? x) (and (real? x) (not (integer? x))))
35(define (even? n) (= (remainder n 2) 0)) 36(define (even? n) (= (remainder n 2) 0))
36(define (odd? n) (not (= (remainder n 2) 0))) 37(define (odd? n) (not (= (remainder n 2) 0)))
37(define (zero? n) (= n 0)) 38(define (zero? n) (= n 0))
38(define (positive? n) (> n 0)) 39(define (positive? n) (> n 0))
41(define rational? real?) 42(define rational? real?)
42(define (abs n) (if (>= n 0) n (- n))) 43(define (abs n) (if (>= n 0) n (- n)))
43(define (exact->inexact n) (* n 1.0)) 44(define (exact->inexact n) (* n 1.0))
44(define (<> n1 n2) (not (= n1 n2))) 45(define (<> n1 n2) (not (= n1 n2)))
45 46
46; min and max must return inexact if any arg is inexact; use (+ n 0.0) 47; min and max must return inexact if any arg is inexact
47(define (max . lst) 48(define (max . lst)
48 (foldr (lambda (a b) 49 (foldr (lambda (a b)
49 (if (> a b) 50 (if (> a b)
50 (if (exact? b) a (+ a 0.0)) 51 (if (exact? b) a (exact->inexact a))
51 (if (exact? a) b (+ b 0.0)))) 52 (if (exact? a) b (exact->inexact b))))
52 (car lst) (cdr lst))) 53 (car lst) (cdr lst)))
53(define (min . lst) 54(define (min . lst)
54 (foldr (lambda (a b) 55 (foldr (lambda (a b)
55 (if (< a b) 56 (if (< a b)
56 (if (exact? b) a (+ a 0.0)) 57 (if (exact? b) a (exact->inexact a))
57 (if (exact? a) b (+ b 0.0)))) 58 (if (exact? a) b (exact->inexact b))))
58 (car lst) (cdr lst))) 59 (car lst) (cdr lst)))
59 60
60(define (succ x) (+ x 1)) 61(define (succ x) (+ x 1))
61(define (pred x) (- x 1)) 62(define (pred x) (- x 1))
62(define gcd 63(define gcd

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines