summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2011-12-15 15:46:49 -0800
committerKaz Kylheku <kaz@kylheku.com>2011-12-15 15:46:49 -0800
commit13c9609500c02a10fbea9cd833615a4ceee7dd43 (patch)
treeb90cef4353a2a3855d98c8e2e2f6bb4272604f34 /lib.c
parente3390f1ed75d58f78218acf22c2a9209a88a14a2 (diff)
downloadtxr-13c9609500c02a10fbea9cd833615a4ceee7dd43.tar.gz
txr-13c9609500c02a10fbea9cd833615a4ceee7dd43.tar.bz2
txr-13c9609500c02a10fbea9cd833615a4ceee7dd43.zip
* eval.c (eval_init): not added as synonym for null.
* lib.c (copy_list): Use list_collect_append rather than list_collect_terminate. (append2, appendv): Simplified using new list_collect_append. (nappend2): Simplified using new list_collect_nconc. * lib.h (list_collect): Added check for accidental usage of list_collect after list_append, since PTAIL has different semantics. (list_collect_nconc, list_collect_append): Semantics fixed so that append collecting works more like the Common Lisp append function, allowing trailing atoms or a lone atom. The meaning of PTAIL is changed, however. Now PTAIL actually tracks the head of the most recently appended segment. Each append operation has to first traverse the previously added piece to get to the end. (list_collect_terminate): Macro removed. * match.c (v_gather): Removed useless use of list_collect_terminate. * parser.y: Some headers added that are needed by list_collect. * txr.1: Documented append, list, atom, null, not, consp, make-lazy-cons, lcons-fun, listp, proper-listp, length-list, mapcar, mappend, and apply.
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c38
1 files changed, 13 insertions, 25 deletions
diff --git a/lib.c b/lib.c
index 8e1652e7..9c3f1e34 100644
--- a/lib.c
+++ b/lib.c
@@ -319,14 +319,14 @@ val push(val value, val *plist)
val copy_list(val list)
{
- list_collect_decl (out, tail);
+ list_collect_decl (out, ptail);
while (consp(list)) {
- list_collect(tail, car(list));
+ list_collect(ptail, car(list));
list = cdr(list);
}
- list_collect_terminate(tail, list);
+ list_collect_append(ptail, list);
return out;
}
@@ -359,14 +359,11 @@ val reverse(val in)
val append2(val list1, val list2)
{
- list_collect_decl (out, tail);
+ list_collect_decl (out, ptail);
- while (list1) {
- list_collect(tail, car(list1));
- list1 = cdr(list1);
- }
+ list_collect_append (ptail, list1);
+ list_collect_append (ptail, list2);
- list_collect_terminate(tail, list2);
return out;
}
@@ -376,14 +373,9 @@ val appendv(val lists)
for (; lists; lists = cdr(lists)) {
val item = car(lists);
- if (consp(item)) {
- list_collect_append(ptail, car(lists));
- } else {
- if (cdr(lists))
- uw_throwf(error_s, lit("append: ~s is not a list"), item, nao);
- list_collect_terminate(ptail, item);
- return out;
- }
+ if (listp(*ptail))
+ uw_throwf(error_s, lit("append: ~s is not a list"), *ptail, nao);
+ list_collect_append(ptail, item);
}
return out;
@@ -391,16 +383,12 @@ val appendv(val lists)
val nappend2(val list1, val list2)
{
- val temp, iter;
-
- if (list1 == nil)
- return list2;
+ list_collect_decl (out, ptail);
- for (iter = list1; (temp = cdr(iter)) != nil; iter = temp)
- ; /* empty */
+ list_collect_nconc (ptail, list1);
+ list_collect_nconc (ptail, list2);
- *cdr_l(iter) = list2;
- return list1;
+ return out;
}
val ldiff(val list1, val list2)