add pic_append
This commit is contained in:
parent
a443d9e3f6
commit
7865cfe9b3
|
@ -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);
|
||||
|
|
17
src/pair.c
17
src/pair.c
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue