I'm having trouble with functions that are n-ary, for example, =, <, etc. I'm trying to implement = first of all. All I have is the following (it's n开发者_如何学运维ot very much).
(define builtin-= =)
(define (b= x y) (builtin-= x y))
(define (= . z)
(if (null? z) #f
(b= (car z) (apply = (cdr z)))))
However, this results in either infinite recursion or heap overflow when I run (= 2 3) or any other similar call.
Thanks.
I figured it out.
(define builtin-= =)
(define (b= x y) (builtin-= x y))
(define (= . z)
(if (or (null? z) (null? (cdr z)))
#t
(and (equal? (car z) (cadr z))
(= (cdr z)))))
I have another problem though. I'm trying to do this for < also. So, equal? won't work.
精彩评论