* Added even? and odd? primitives.

This commit is contained in:
Abdulaziz Ghuloum 2007-01-13 22:32:54 -05:00
parent fe89891d96
commit 872a5e2e9e
5 changed files with 33 additions and 1 deletions

Binary file not shown.

View File

@ -32,6 +32,17 @@ ikrt_positive_bn(ikp x){
}
}
ikp
ikrt_even_bn(ikp x){
int fst = (int)ref(x, wordsize-vector_tag);
if(fst & 1){
return false_object;
} else {
return true_object;
}
}
ikp
ikrt_fxfxplus(ikp x, ikp y, ikpcb* pcb){

Binary file not shown.

View File

@ -175,7 +175,24 @@
(define even-bignum?
(lambda (x) (error 'even-bignum? "not implemented")))
(lambda (x)
(foreign-call "ikrt_even_bn" x)))
(define ($fxeven? x)
($fxzero? ($fxlogand x 1)))
(define (even? x)
(cond
[(fixnum? x) ($fxeven? x)]
[(bignum? x) (even-bignum? x)]
[else (error 'even? "~s is not an integer" x)]))
(define (odd? x)
(not
(cond
[(fixnum? x) ($fxeven? x)]
[(bignum? x) (even-bignum? x)]
[else (error 'odd? "~s is not an integer" x)])))
(define number->string
(lambda (x)
@ -410,4 +427,7 @@
[(fixnum? x) (#%$fx< x 0)]
[(bignum? x) (not (positive-bignum? x))]
[else (error 'negative? "~s is not a number" x)])))
(primitive-set! 'even? even?)
(primitive-set! 'odd? odd?)
)

View File

@ -88,6 +88,7 @@
time-it
posix-fork fork waitpid env environ
pretty-print
even? odd?
))
(define system-primitives