add pic_list_ref and pic_list_tail

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

View File

@ -29,6 +29,9 @@ pic_value pic_cadr(pic_state *, pic_value);
pic_value pic_cdar(pic_state *, pic_value);
pic_value pic_cddr(pic_state *, pic_value);
pic_value pic_list_tail(pic_state *, pic_value ,int);
pic_value pic_list_ref(pic_state *, pic_value, int);
#if defined(__cplusplus)
}
#endif

View File

@ -180,6 +180,21 @@ pic_cddr(pic_state *pic, pic_value v)
return pic_cdr(pic, pic_cdr(pic, v));
}
pic_value
pic_list_tail(pic_state *pic, pic_value list, int i)
{
while (i-- > 0) {
list = pic_cdr(pic, list);
}
return list;
}
pic_value
pic_list_ref(pic_state *pic, pic_value list, int i)
{
return pic_car(pic, pic_list_tail(pic, list, i));
}
static pic_value
pic_pair_pair_p(pic_state *pic)
{