add eqv? and equal?
This commit is contained in:
parent
27dc840118
commit
fc42c71304
|
@ -113,6 +113,8 @@
|
|||
(if-false (cons 'cond (cdr clauses))))
|
||||
(list 'if test if-true if-false)))))
|
||||
|
||||
(define else #t)
|
||||
|
||||
(define-macro (and . exprs)
|
||||
(if (null? exprs)
|
||||
#t
|
||||
|
@ -141,3 +143,14 @@
|
|||
(list 'quasiquote (car x))
|
||||
(list 'quasiquote (cdr x))))))
|
||||
(#t x)))
|
||||
|
||||
(define (equal? x y)
|
||||
(cond
|
||||
((eqv? x y)
|
||||
#t)
|
||||
((and (pair? x) (pair? y))
|
||||
(and (equal? (car x) (car y))
|
||||
(equal? (cdr x) (cdr y))))
|
||||
(else
|
||||
#f)))
|
||||
|
||||
|
|
11
src/bool.c
11
src/bool.c
|
@ -12,6 +12,16 @@ pic_bool_eq_p(pic_state *pic)
|
|||
return pic_bool_value(pic_eq_p(x, y));
|
||||
}
|
||||
|
||||
static pic_value
|
||||
pic_bool_eqv_p(pic_state *pic)
|
||||
{
|
||||
pic_value x, y;
|
||||
|
||||
pic_get_args(pic, "oo", &x, &y);
|
||||
|
||||
return pic_bool_value(pic_eqv_p(x, y));
|
||||
}
|
||||
|
||||
/* TODO: replace it with native opcode */
|
||||
static pic_value
|
||||
pic_bool_not(pic_state *pic)
|
||||
|
@ -37,6 +47,7 @@ void
|
|||
pic_init_bool(pic_state *pic)
|
||||
{
|
||||
pic_defun(pic, "eq?", pic_bool_eq_p);
|
||||
pic_defun(pic, "eqv?", pic_bool_eqv_p);
|
||||
|
||||
pic_defun(pic, "not", pic_bool_not);
|
||||
pic_defun(pic, "boolean?", pic_bool_boolean_p);
|
||||
|
|
|
@ -225,6 +225,12 @@ pic_eq_p(pic_value x, pic_value y)
|
|||
return x.u.data == y.u.data;
|
||||
}
|
||||
|
||||
bool
|
||||
pic_eqv_p(pic_value x, pic_value y)
|
||||
{
|
||||
return x.u.data == y.u.data;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
bool
|
||||
|
|
Loading…
Reference in New Issue