From 291b5f86e063dce60db3c826c166103cc98b3fcc Mon Sep 17 00:00:00 2001 From: JeffBezanson Date: Wed, 22 Apr 2009 01:40:10 +0000 Subject: [PATCH] fixing nconc on long argument lists --- femtolisp/builtins.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/femtolisp/builtins.c b/femtolisp/builtins.c index 40675e8..8e9ea19 100644 --- a/femtolisp/builtins.c +++ b/femtolisp/builtins.c @@ -30,23 +30,27 @@ static value_t fl_nconc(value_t *args, u_int32_t nargs) { if (nargs == 0) return NIL; - value_t first=NIL; + value_t lst, first=NIL; value_t *pcdr = &first; cons_t *c; int a; - for(a=0; a < (int)nargs-1; a++) { - if (iscons(args[a])) { - *pcdr = args[a]; - c = (cons_t*)ptr(args[a]); + FOR_ARGS(a, 0, lst, args) { + // skip last + if ((nargs > MAX_ARGS && !iscons(args[MAX_ARGS])) || + (nargs <= MAX_ARGS && a == nargs-1)) + break; + if (iscons(lst)) { + *pcdr = lst; + c = (cons_t*)ptr(lst); while (iscons(c->cdr)) c = (cons_t*)ptr(c->cdr); pcdr = &c->cdr; } - else if (args[a] != NIL) { - type_error("nconc", "cons", args[a]); + else if (lst != NIL) { + type_error("nconc", "cons", lst); } } - *pcdr = args[a]; + *pcdr = lst; return first; }