add pic_reverse
This commit is contained in:
parent
114d6b708b
commit
0c1babb6c5
|
@ -8,6 +8,8 @@ pic_value pic_cdr(pic_state *, pic_value);
|
|||
bool pic_list_p(pic_state *, pic_value);
|
||||
pic_value pic_list(pic_state *, size_t, ...);
|
||||
|
||||
pic_value pic_reverse(pic_state *, pic_value);
|
||||
|
||||
pic_value pic_assq(pic_state *, pic_value key, pic_value assoc);
|
||||
pic_value pic_acons(pic_state *, pic_value key, pic_value val, pic_value assoc);
|
||||
|
||||
|
|
|
@ -389,21 +389,13 @@ pic_gen(pic_state *pic, struct pic_irep *irep, pic_value obj, struct pic_env *en
|
|||
}
|
||||
}
|
||||
|
||||
static pic_value
|
||||
reverse(pic_state *pic, pic_value list, pic_value acc)
|
||||
{
|
||||
if (pic_nil_p(list))
|
||||
return acc;
|
||||
return reverse(pic, pic_cdr(pic, list), pic_cons(pic, pic_car(pic, list), acc));
|
||||
}
|
||||
|
||||
static void
|
||||
pic_gen_call(pic_state *pic, struct pic_irep *irep, pic_value obj, struct pic_env *env)
|
||||
{
|
||||
pic_value seq;
|
||||
int i = 0;
|
||||
|
||||
seq = reverse(pic, obj, pic_nil_value());
|
||||
seq = pic_reverse(pic, obj);
|
||||
for (; ! pic_nil_p(seq); seq = pic_cdr(pic, seq)) {
|
||||
pic_value v;
|
||||
|
||||
|
|
11
src/pair.c
11
src/pair.c
|
@ -48,6 +48,17 @@ pic_list_p(pic_state *pic, pic_value obj)
|
|||
return pic_nil_p(obj);
|
||||
}
|
||||
|
||||
pic_value
|
||||
pic_reverse(pic_state *pic, pic_value list)
|
||||
{
|
||||
pic_value v, acc = pic_nil_value();
|
||||
|
||||
for (v = list; ! pic_nil_p(v); v = pic_cdr(pic ,v)) {
|
||||
acc = pic_cons(pic, pic_car(pic, v), acc);
|
||||
}
|
||||
return acc;
|
||||
}
|
||||
|
||||
pic_value
|
||||
pic_assq(pic_state *pic, pic_value key, pic_value assoc)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue