diff --git a/include/picrin/pair.h b/include/picrin/pair.h index 82584b0c..2d5a02b2 100644 --- a/include/picrin/pair.h +++ b/include/picrin/pair.h @@ -5,6 +5,7 @@ pic_value pic_cons(pic_state *, pic_value, pic_value); pic_value pic_car(pic_state *, pic_value); 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_assq(pic_state *, pic_value key, pic_value assoc); diff --git a/src/pair.c b/src/pair.c index bbd17e5f..63fa1e40 100644 --- a/src/pair.c +++ b/src/pair.c @@ -39,6 +39,15 @@ pic_cdr(pic_state *pic, pic_value obj) return pair->cdr; } +bool +pic_list_p(pic_state *pic, pic_value obj) +{ + while (pic_pair_p(obj)) + obj = pic_pair_ptr(obj)->cdr; + + return pic_nil_p(obj); +} + pic_value pic_assq(pic_state *pic, pic_value key, pic_value assoc) {