From 1b3eda6e08018797702e29c233c8a1e59dd19760 Mon Sep 17 00:00:00 2001 From: Juan Jose Garcia Ripoll Date: Sat, 14 Nov 2009 17:37:27 +0100 Subject: [PATCH] APPEND copied also the last argument. --- src/CHANGELOG | 2 ++ src/c/list.d | 51 +++++++++++++++++++-------------------------------- 2 files changed, 21 insertions(+), 32 deletions(-) diff --git a/src/CHANGELOG b/src/CHANGELOG index 1ed190945..ef27bc2ab 100755 --- a/src/CHANGELOG +++ b/src/CHANGELOG @@ -49,6 +49,8 @@ ECL 9.11.1: - FIND-SYMBOL accepted string designators instead of just strings, as mandated by the ANSI specification. + - APPEND copied also the last argument. + * Sockets: - The socket option TCP_NODELAY option has been fixed: it was improperly using diff --git a/src/c/list.d b/src/c/list.d index 486b6dfba..a1258c5ec 100644 --- a/src/c/list.d +++ b/src/c/list.d @@ -185,58 +185,45 @@ cl_cdr(cl_object x) @(return head) @) -static cl_object -append_into(cl_object tail, cl_object l) +static cl_object * +append_into(cl_object head, cl_object *tail, cl_object l) { - if (!Null(ECL_CONS_CDR(tail))) { + if (!Null(*tail)) { /* (APPEND '(1 . 2) 3) */ - FEtype_error_proper_list(tail); + FEtype_error_proper_list(head); } while (CONSP(l)) { cl_object cons = ecl_list1(ECL_CONS_CAR(l)); - ECL_RPLACD(tail, cons); - tail = cons; + *tail = cons; + tail = &ECL_CONS_CDR(cons); l = ECL_CONS_CDR(l); } - ECL_RPLACD(tail, l); + *tail = l; return tail; } @(defun append (&rest rest) - cl_object head = Cnil, tail = Cnil; + cl_object head = Cnil, *tail = &head; @ - while (narg--) { + for (; narg > 1; narg--) { cl_object other = cl_va_arg(rest); - if (Null(head)) { - head = other; - if (Null(head)) - continue; - if (!LISTP(head)) { - if (narg) { - /* (APPEND atom whatever) */ - FEtype_error_list(other); - } - /* (APPEND atom) */ - break; - } - other = ECL_CONS_CDR(head); - tail = head = ecl_list1(ECL_CONS_CAR(head)); - } - tail = append_into(tail, other); + tail = append_into(head, tail, other); } + if (narg) { + *tail = cl_va_arg(rest); + } @(return head) @) cl_object ecl_append(cl_object x, cl_object y) { - cl_object head, tail; - if (Null(x)) - return y; - if (!LISTP(x)) - FEtype_error_list(x); - head = tail = ecl_list1(ECL_CONS_CAR(x)); - append_into(append_into(tail, ECL_CONS_CDR(x)), y); + cl_object head = Cnil; + cl_object *tail = &head; + if (!Null(x)) { + tail = append_into(head, tail, x); + } + *tail = y; return head; }