ref: 291b5f86e063dce60db3c826c166103cc98b3fcc
parent: 2bf87ede4f47966d26b90e0c66989789f9c55a1d
author: JeffBezanson <jeff.bezanson@gmail.com>
date: Tue Apr 21 21:40:10 EDT 2009
fixing nconc on long argument lists
--- a/femtolisp/builtins.c
+++ b/femtolisp/builtins.c
@@ -30,23 +30,27 @@
{
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;
}