From a4a63314a991a749610e54b50b1b4eafad929e05 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sat, 1 Feb 2014 16:04:57 +0900 Subject: [PATCH] add pic_for_each macro --- include/picrin/pair.h | 8 ++++++++ 1 file changed, 8 insertions(+) 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);