diff --git a/include/picrin/pair.h b/include/picrin/pair.h index a9f133a3..5c23630c 100644 --- a/include/picrin/pair.h +++ b/include/picrin/pair.h @@ -18,6 +18,14 @@ pic_value pic_list(pic_state *, size_t, ...); pic_value pic_list_from_array(pic_state *, size_t, pic_value *); pic_value pic_make_list(pic_state *, int, pic_value); +#define PIC_FOR_EACH_HELPER(var, tmp, list) \ + for (pic_value tmp = (list); \ + pic_nil_p(tmp) ? false : ((var = pic_car(pic, tmp)), true); \ + tmp = pic_cdr(pic, tmp)) + +#define pic_for_each(var, list) \ + PIC_FOR_EACH_HELPER(var, GENSYM(pic_for_each_tmp__), list) \ + 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);