add eqv? and equal?
This commit is contained in:
parent
27dc840118
commit
fc42c71304
|
@ -113,6 +113,8 @@
|
||||||
(if-false (cons 'cond (cdr clauses))))
|
(if-false (cons 'cond (cdr clauses))))
|
||||||
(list 'if test if-true if-false)))))
|
(list 'if test if-true if-false)))))
|
||||||
|
|
||||||
|
(define else #t)
|
||||||
|
|
||||||
(define-macro (and . exprs)
|
(define-macro (and . exprs)
|
||||||
(if (null? exprs)
|
(if (null? exprs)
|
||||||
#t
|
#t
|
||||||
|
@ -141,3 +143,14 @@
|
||||||
(list 'quasiquote (car x))
|
(list 'quasiquote (car x))
|
||||||
(list 'quasiquote (cdr x))))))
|
(list 'quasiquote (cdr x))))))
|
||||||
(#t 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));
|
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 */
|
/* TODO: replace it with native opcode */
|
||||||
static pic_value
|
static pic_value
|
||||||
pic_bool_not(pic_state *pic)
|
pic_bool_not(pic_state *pic)
|
||||||
|
@ -37,6 +47,7 @@ void
|
||||||
pic_init_bool(pic_state *pic)
|
pic_init_bool(pic_state *pic)
|
||||||
{
|
{
|
||||||
pic_defun(pic, "eq?", pic_bool_eq_p);
|
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, "not", pic_bool_not);
|
||||||
pic_defun(pic, "boolean?", pic_bool_boolean_p);
|
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;
|
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
|
#else
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
Loading…
Reference in New Issue