2007-05-05 03:24:33 -04:00
|
|
|
|
|
|
|
(library (ikarus predicates)
|
2007-05-05 03:34:59 -04:00
|
|
|
|
2007-05-20 23:23:54 -04:00
|
|
|
(export fixnum? flonum? bignum? ratnum? number? complex? real? rational?
|
2007-09-03 00:34:53 -04:00
|
|
|
integer? exact? inexact? eof-object? bwp-object? immediate?
|
2007-05-15 12:42:52 -04:00
|
|
|
boolean? char? vector? bytevector? string? procedure? null? pair?
|
2007-08-28 15:03:21 -04:00
|
|
|
symbol? code? not weak-pair? eq? eqv? equal? boolean=?
|
2007-09-12 03:10:54 -04:00
|
|
|
symbol=? finite? infinite? nan? real-valued?
|
|
|
|
rational-valued? integer-valued?)
|
2007-05-05 03:34:59 -04:00
|
|
|
|
2007-05-05 03:24:33 -04:00
|
|
|
(import
|
2007-05-20 23:23:54 -04:00
|
|
|
(except (ikarus) fixnum? flonum? bignum? ratnum? number? complex? real?
|
2007-09-03 00:34:53 -04:00
|
|
|
rational? integer? exact? inexact? eof-object? bwp-object?
|
2007-05-15 12:42:52 -04:00
|
|
|
immediate? boolean? char? vector? bytevector? string? procedure?
|
2007-05-06 22:48:10 -04:00
|
|
|
null? pair? weak-pair? symbol? code? not eq? eqv? equal?
|
2007-09-12 02:44:19 -04:00
|
|
|
port? input-port? output-port? boolean=? symbol=?
|
2007-09-12 03:10:54 -04:00
|
|
|
finite? infinite? nan? real-valued? rational-valued?
|
|
|
|
integer-valued?)
|
2007-05-06 18:43:04 -04:00
|
|
|
(ikarus system $fx)
|
2007-06-13 02:03:30 -04:00
|
|
|
(ikarus system $flonums)
|
2007-05-06 18:43:04 -04:00
|
|
|
(ikarus system $pairs)
|
|
|
|
(ikarus system $chars)
|
|
|
|
(ikarus system $strings)
|
|
|
|
(ikarus system $vectors)
|
2007-05-20 23:23:54 -04:00
|
|
|
(rename (only (ikarus) fixnum? flonum? bignum? ratnum? eof-object?
|
2007-05-05 06:15:25 -04:00
|
|
|
bwp-object? immediate? boolean? char? vector? string?
|
2007-05-15 12:42:52 -04:00
|
|
|
bytevector? procedure? null? pair? symbol? code? eq?
|
2007-05-05 17:44:24 -04:00
|
|
|
port? input-port? output-port?)
|
2007-05-05 03:24:33 -04:00
|
|
|
(fixnum? sys:fixnum?)
|
|
|
|
(flonum? sys:flonum?)
|
2007-05-05 03:27:53 -04:00
|
|
|
(bignum? sys:bignum?)
|
2007-05-20 23:23:54 -04:00
|
|
|
(ratnum? sys:ratnum?)
|
2007-05-05 03:27:53 -04:00
|
|
|
(eof-object? sys:eof-object?)
|
2007-05-05 06:15:25 -04:00
|
|
|
(bwp-object? sys:bwp-object?)
|
2007-05-05 03:34:59 -04:00
|
|
|
(immediate? sys:immediate?)
|
|
|
|
(boolean? sys:boolean?)
|
|
|
|
(char? sys:char?)
|
|
|
|
(vector? sys:vector?)
|
2007-05-15 12:42:52 -04:00
|
|
|
(bytevector? sys:bytevector?)
|
2007-05-05 03:34:59 -04:00
|
|
|
(string? sys:string?)
|
|
|
|
(procedure? sys:procedure?)
|
|
|
|
(null? sys:null?)
|
|
|
|
(pair? sys:pair?)
|
2007-05-05 05:09:15 -04:00
|
|
|
(symbol? sys:symbol?)
|
2007-05-06 22:48:10 -04:00
|
|
|
(code? sys:code?)
|
2007-05-05 17:44:24 -04:00
|
|
|
(eq? sys:eq?)
|
|
|
|
(port? sys:port?)
|
|
|
|
(input-port? sys:input-port?)
|
|
|
|
(output-port? sys:output-port?)
|
|
|
|
))
|
2007-05-05 03:24:33 -04:00
|
|
|
|
|
|
|
(define fixnum?
|
|
|
|
(lambda (x) (sys:fixnum? x)))
|
|
|
|
|
|
|
|
(define bignum?
|
|
|
|
(lambda (x) (sys:bignum? x)))
|
|
|
|
|
2007-05-20 23:23:54 -04:00
|
|
|
(define ratnum?
|
|
|
|
(lambda (x) (sys:ratnum? x)))
|
|
|
|
|
2007-05-05 03:24:33 -04:00
|
|
|
(define flonum?
|
|
|
|
(lambda (x) (sys:flonum? x)))
|
|
|
|
|
|
|
|
(define number?
|
|
|
|
(lambda (x)
|
|
|
|
(or (sys:fixnum? x)
|
|
|
|
(sys:bignum? x)
|
2007-05-20 23:23:54 -04:00
|
|
|
(sys:flonum? x)
|
|
|
|
(sys:ratnum? x))))
|
2007-05-05 03:24:33 -04:00
|
|
|
|
|
|
|
(define complex?
|
|
|
|
(lambda (x) (number? x)))
|
|
|
|
|
|
|
|
(define real?
|
|
|
|
(lambda (x) (number? x)))
|
2007-09-12 03:10:54 -04:00
|
|
|
|
|
|
|
(define real-valued?
|
|
|
|
(lambda (x) (number? x)))
|
|
|
|
|
2007-05-05 03:24:33 -04:00
|
|
|
(define rational?
|
|
|
|
(lambda (x)
|
|
|
|
(cond
|
|
|
|
[(sys:fixnum? x) #t]
|
|
|
|
[(sys:bignum? x) #t]
|
2007-05-20 23:23:54 -04:00
|
|
|
[(sys:ratnum? x) #t]
|
2007-06-13 02:03:30 -04:00
|
|
|
[(sys:flonum? x) ($flonum-rational? x)]
|
2007-09-12 03:10:54 -04:00
|
|
|
[else #f])))
|
|
|
|
|
|
|
|
(define rational-valued?
|
|
|
|
(lambda (x) (rational? x)))
|
2007-05-05 03:24:33 -04:00
|
|
|
|
|
|
|
(define integer?
|
|
|
|
(lambda (x)
|
|
|
|
(cond
|
|
|
|
[(sys:fixnum? x) #t]
|
|
|
|
[(sys:bignum? x) #t]
|
2007-05-20 23:23:54 -04:00
|
|
|
[(sys:ratnum? x) #f]
|
2007-06-13 02:03:30 -04:00
|
|
|
[(sys:flonum? x) ($flonum-integer? x)]
|
2007-05-05 03:24:33 -04:00
|
|
|
[else #f])))
|
|
|
|
|
2007-09-12 03:10:54 -04:00
|
|
|
(define integer-valued?
|
|
|
|
(lambda (x) (integer? x)))
|
|
|
|
|
2007-05-05 03:24:33 -04:00
|
|
|
(define exact?
|
|
|
|
(lambda (x)
|
|
|
|
(cond
|
|
|
|
[(sys:fixnum? x) #t]
|
|
|
|
[(sys:bignum? x) #t]
|
2007-06-13 02:03:30 -04:00
|
|
|
[(sys:ratnum? x) #t]
|
2007-05-05 03:24:33 -04:00
|
|
|
[(sys:flonum? x) #f]
|
|
|
|
[else
|
2007-05-05 03:27:53 -04:00
|
|
|
(error 'exact? "~s is not a number" x)])))
|
|
|
|
|
2007-09-03 00:34:53 -04:00
|
|
|
|
|
|
|
(define inexact?
|
|
|
|
(lambda (x)
|
|
|
|
(cond
|
|
|
|
[(sys:flonum? x) #t]
|
|
|
|
[(sys:fixnum? x) #f]
|
|
|
|
[(sys:bignum? x) #f]
|
|
|
|
[(sys:ratnum? x) #f]
|
|
|
|
[else
|
|
|
|
(error 'inexact? "~s is not a number" x)])))
|
|
|
|
|
2007-09-12 02:44:19 -04:00
|
|
|
(define finite?
|
|
|
|
(lambda (x)
|
|
|
|
(cond
|
|
|
|
[(sys:flonum? x) (flfinite? x)]
|
|
|
|
[(sys:fixnum? x) #t]
|
|
|
|
[(sys:bignum? x) #t]
|
|
|
|
[(sys:ratnum? x) #t]
|
|
|
|
[else
|
|
|
|
(error 'finite? "~s is not a number" x)])))
|
|
|
|
|
|
|
|
(define infinite?
|
|
|
|
(lambda (x)
|
|
|
|
(cond
|
|
|
|
[(sys:flonum? x) (flinfinite? x)]
|
|
|
|
[(sys:fixnum? x) #f]
|
|
|
|
[(sys:bignum? x) #f]
|
|
|
|
[(sys:ratnum? x) #f]
|
|
|
|
[else
|
|
|
|
(error 'infinite? "~s is not a number" x)])))
|
|
|
|
|
|
|
|
(define nan?
|
|
|
|
(lambda (x)
|
|
|
|
(cond
|
|
|
|
[(sys:flonum? x) (flnan? x)]
|
|
|
|
[(sys:fixnum? x) #f]
|
|
|
|
[(sys:bignum? x) #f]
|
|
|
|
[(sys:ratnum? x) #f]
|
|
|
|
[else
|
|
|
|
(error 'nan? "~s is not a number" x)])))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-05-05 03:34:59 -04:00
|
|
|
(define eof-object? (lambda (x) (sys:eof-object? x)))
|
2007-05-05 06:15:25 -04:00
|
|
|
(define bwp-object? (lambda (x) (sys:bwp-object? x)))
|
2007-05-05 03:34:59 -04:00
|
|
|
(define immediate? (lambda (x) (sys:immediate? x)))
|
|
|
|
(define boolean? (lambda (x) (sys:boolean? x)))
|
|
|
|
(define char? (lambda (x) (sys:char? x)))
|
|
|
|
(define vector? (lambda (x) (sys:vector? x)))
|
2007-05-15 12:42:52 -04:00
|
|
|
(define bytevector? (lambda (x) (sys:bytevector? x)))
|
2007-05-05 03:34:59 -04:00
|
|
|
(define string? (lambda (x) (sys:string? x)))
|
|
|
|
(define procedure? (lambda (x) (sys:procedure? x)))
|
|
|
|
(define null? (lambda (x) (sys:null? x)))
|
|
|
|
(define pair? (lambda (x) (sys:pair? x)))
|
|
|
|
(define symbol? (lambda (x) (sys:symbol? x)))
|
2007-05-06 22:48:10 -04:00
|
|
|
(define code? (lambda (x) (sys:code? x)))
|
2007-05-05 06:18:29 -04:00
|
|
|
|
|
|
|
|
|
|
|
(define weak-pair?
|
|
|
|
(lambda (x)
|
|
|
|
(and (pair? x)
|
|
|
|
(foreign-call "ikrt_is_weak_pair" x))))
|
|
|
|
|
2007-05-05 04:28:40 -04:00
|
|
|
(define not (lambda (x) (if x #f #t)))
|
2007-05-05 05:09:15 -04:00
|
|
|
|
|
|
|
(define eq? (lambda (x y) (sys:eq? x y)))
|
|
|
|
|
2007-05-05 05:10:38 -04:00
|
|
|
(define eqv?
|
|
|
|
(lambda (x y)
|
|
|
|
(or (sys:eq? x y)
|
|
|
|
(and (number? x) (number? y) (= x y)))))
|
2007-05-05 05:35:09 -04:00
|
|
|
|
2007-08-28 15:03:21 -04:00
|
|
|
(define boolean=?
|
|
|
|
(lambda (x y)
|
|
|
|
(if (sys:boolean? x)
|
|
|
|
(if (sys:eq? x y)
|
|
|
|
#t
|
|
|
|
(if (sys:boolean? y)
|
|
|
|
#f
|
|
|
|
(error 'boolean=? "~s is not a boolean" y)))
|
|
|
|
(error 'boolean=? "~s is not a boolean" x))))
|
|
|
|
|
2007-05-05 05:35:09 -04:00
|
|
|
|
2007-08-28 15:03:21 -04:00
|
|
|
(define symbol=?
|
|
|
|
(lambda (x y)
|
|
|
|
(if (sys:symbol? x)
|
|
|
|
(if (sys:eq? x y)
|
|
|
|
#t
|
|
|
|
(if (sys:symbol? y)
|
|
|
|
#f
|
|
|
|
(error 'symbol=? "~s is not a symbol" y)))
|
|
|
|
(error 'symbol=? "~s is not a symbol" x))))
|
2007-05-05 05:35:09 -04:00
|
|
|
|
|
|
|
(module (equal?)
|
|
|
|
(define vector-loop
|
|
|
|
(lambda (x y i n)
|
|
|
|
(or ($fx= i n)
|
|
|
|
(and (equal? ($vector-ref x i) ($vector-ref y i))
|
|
|
|
(vector-loop x y ($fxadd1 i) n)))))
|
|
|
|
(define string-loop
|
|
|
|
(lambda (x y i n)
|
|
|
|
(or ($fx= i n)
|
|
|
|
(and ($char= ($string-ref x i) ($string-ref y i))
|
|
|
|
(string-loop x y ($fxadd1 i) n)))))
|
|
|
|
(define equal?
|
|
|
|
(lambda (x y)
|
|
|
|
(cond
|
|
|
|
[(sys:eq? x y) #t]
|
|
|
|
[(pair? x)
|
|
|
|
(and (pair? y)
|
|
|
|
(equal? ($car x) ($car y))
|
|
|
|
(equal? ($cdr x) ($cdr y)))]
|
|
|
|
[(vector? x)
|
|
|
|
(and (vector? y)
|
|
|
|
(let ([n ($vector-length x)])
|
|
|
|
(and ($fx= n ($vector-length y))
|
|
|
|
(vector-loop x y 0 n))))]
|
|
|
|
[(string? x)
|
|
|
|
(and (string? y)
|
|
|
|
(let ([n ($string-length x)])
|
|
|
|
(and ($fx= n ($string-length y))
|
|
|
|
(string-loop x y 0 n))))]
|
|
|
|
[(number? x) (and (number? y) (= x y))]
|
2007-09-11 00:13:10 -04:00
|
|
|
[(sys:bytevector? x)
|
|
|
|
(and (sys:bytevector? y) (bytevector=? x y))]
|
2007-05-05 05:35:09 -04:00
|
|
|
[else #f]))))
|
|
|
|
|
2007-05-05 17:44:24 -04:00
|
|
|
(define port?
|
|
|
|
(lambda (x) (sys:port? x)))
|
|
|
|
(define input-port?
|
|
|
|
(lambda (x) (sys:input-port? x)))
|
|
|
|
(define output-port?
|
|
|
|
(lambda (x) (sys:output-port? x)))
|
|
|
|
|
|
|
|
|
2007-05-05 03:27:53 -04:00
|
|
|
)
|