implement memq and assq with c
This commit is contained in:
+37
@@ -261,6 +261,21 @@ pic_append(pic_state *pic, pic_value xs, pic_value ys)
|
||||
return ys;
|
||||
}
|
||||
|
||||
pic_value
|
||||
pic_memq(pic_state *pic, pic_value key, pic_value list)
|
||||
{
|
||||
enter:
|
||||
|
||||
if (pic_nil_p(list))
|
||||
return pic_false_value();
|
||||
|
||||
if (pic_eq_p(key, pic_car(pic, list)))
|
||||
return list;
|
||||
|
||||
list = pic_cdr(pic, list);
|
||||
goto enter;
|
||||
}
|
||||
|
||||
pic_value
|
||||
pic_assq(pic_state *pic, pic_value key, pic_value assoc)
|
||||
{
|
||||
@@ -594,6 +609,26 @@ pic_pair_list_copy(pic_state *pic)
|
||||
return pic_list_copy(pic, obj);
|
||||
}
|
||||
|
||||
static pic_value
|
||||
pic_pair_memq(pic_state *pic)
|
||||
{
|
||||
pic_value key, list;
|
||||
|
||||
pic_get_args(pic, "oo", &key, &list);
|
||||
|
||||
return pic_memq(pic, key, list);
|
||||
}
|
||||
|
||||
static pic_value
|
||||
pic_pair_assq(pic_state *pic)
|
||||
{
|
||||
pic_value key, list;
|
||||
|
||||
pic_get_args(pic, "oo", &key, &list);
|
||||
|
||||
return pic_assq(pic, key, list);
|
||||
}
|
||||
|
||||
void
|
||||
pic_init_pair(pic_state *pic)
|
||||
{
|
||||
@@ -618,4 +653,6 @@ pic_init_pair(pic_state *pic)
|
||||
pic_defun(pic, "list-ref", pic_pair_list_ref);
|
||||
pic_defun(pic, "list-set!", pic_pair_list_set);
|
||||
pic_defun(pic, "list-copy", pic_pair_list_copy);
|
||||
pic_defun(pic, "memq", pic_pair_memq);
|
||||
pic_defun(pic, "assq", pic_pair_assq);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user