add pic_append

This commit is contained in:
Yuichi Nishiwaki 2014-01-22 20:57:14 +09:00
parent a443d9e3f6
commit 7865cfe9b3
2 changed files with 18 additions and 0 deletions

View File

@ -19,6 +19,7 @@ pic_value pic_list_from_array(pic_state *, size_t, pic_value *);
int pic_length(pic_state *, pic_value);
pic_value pic_reverse(pic_state *, pic_value);
pic_value pic_append(pic_state *, pic_value, pic_value);
pic_value pic_assq(pic_state *, pic_value key, pic_value assoc);
pic_value pic_assoc(pic_state *, pic_value key, pic_value assoc);

View File

@ -114,6 +114,23 @@ pic_reverse(pic_state *pic, pic_value list)
return acc;
}
pic_value
pic_append(pic_state *pic, pic_value xs, pic_value ys)
{
int ai = pic_gc_arena_preserve(pic);
if (pic_nil_p(xs)) {
return ys;
}
else {
xs = pic_cons(pic, pic_car(pic, xs), pic_append(pic, pic_cdr(pic, xs), ys));
}
pic_gc_arena_restore(pic, ai);
pic_gc_protect(pic, xs);
return xs;
}
pic_value
pic_assq(pic_state *pic, pic_value key, pic_value assoc)
{