diff --git a/lisp/kernel.gl b/lisp/kernel.gl index b6dbac5..fdcd3f1 100644 --- a/lisp/kernel.gl +++ b/lisp/kernel.gl @@ -113,4 +113,4 @@ Spec is of the form (VARIABLE LIST &optional RETURN-FORM)." (princ datum print-char-fun) (terpri print-char-fun)) -(princln (nconc '(1 2) '(4 . 6) '(3 4))) +(princln (append '(1 2) '(3 4))) diff --git a/src/list.c b/src/list.c index 029565d..fc3b99d 100644 --- a/src/list.c +++ b/src/list.c @@ -93,7 +93,30 @@ DEFUN(reverse, "reverse", (LispVal * list), "(list)", "") { } DEFUN(append, "append", (LispVal * lists), "(&rest lists)", "") { - return Qnil; + LispVal *out = Qnil; + LispVal *end = Qnil; + DOTAILS(rest, lists) { + LispVal *cur = XCAR(rest); + CHECK_LISTP(cur); + if (NILP(cur)) { + continue; + } + if (!NILP(XCDR(rest))) { + cur = Fcopy_list(cur); + } + if (NILP(out)) { + out = cur; + } else { + RPLACD(end, cur); + } + if (!NILP(XCDR(rest))) { + end = Flast(cur); + if (!NILP(XCDR(end))) { + signal_type_error(cur, Qlist); + } + } + } + return out; } DEFUN(nconc, "nconc", (LispVal * lists), "(&rest lists)", "") {