* Added even? and odd? primitives.
This commit is contained in:
parent
fe89891d96
commit
872a5e2e9e
BIN
bin/ikarus
BIN
bin/ikarus
Binary file not shown.
|
@ -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){
|
||||
|
|
BIN
src/ikarus.boot
BIN
src/ikarus.boot
Binary file not shown.
|
@ -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?)
|
||||
)
|
||||
|
|
|
@ -88,6 +88,7 @@
|
|||
time-it
|
||||
posix-fork fork waitpid env environ
|
||||
pretty-print
|
||||
even? odd?
|
||||
))
|
||||
|
||||
(define system-primitives
|
||||
|
|
Loading…
Reference in New Issue