summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog13
-rw-r--r--eval.c7
-rw-r--r--lib.c18
-rw-r--r--txr.15
4 files changed, 33 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index c2fc1205..3ff7b5bf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2014-06-03 Kaz Kylheku <kaz@kylheku.com>
+
+ Documenting the return value of rplaca and rplacd, and changing
+ it to be the cell, rather than the new value.
+
+ * eval.c (transform_op): Fix use of rplacd that uses return value.
+ (force): Likewise.
+
+ * lib.c (rplaca, rplacd): Return cons.
+ (rem_lazy_rec, obj_init): Fix use of rplacd that uses return value.
+
+ * txr.1: Documented.
+
2014-05-20 Kaz Kylheku <kaz@kylheku.com>
The call operator should be a function!
diff --git a/eval.c b/eval.c
index de1180ed..bbd76c2d 100644
--- a/eval.c
+++ b/eval.c
@@ -2284,8 +2284,9 @@ static val transform_op(val forms, val syms, val rg)
val newsyms = syms;
val new_p;
val cell = acons_new_c(vararg, mkcloc(new_p), mkcloc(newsyms));
- val sym = if3(new_p, rplacd(cell, gensym(format_op_arg(vararg))),
- cdr(cell));
+ val sym = cdr(if3(new_p,
+ rplacd(cell, gensym(format_op_arg(vararg))),
+ cell));
cons_bind (outsyms, outforms, transform_op(re, newsyms, rg));
return cons(outsyms, rlcp(cons(sym, outforms), outforms));
} else if (vararg == rest_s) {
@@ -2933,7 +2934,7 @@ static val force(val promise)
return cdr(promise);
rplaca(promise, nil);
- return rplacd(promise, funcall(cdr(promise)));
+ return cdr(rplacd(promise, funcall(cdr(promise))));
}
static val errno_wrap(val newval)
diff --git a/lib.c b/lib.c
index fed06664..5c51ed7f 100644
--- a/lib.c
+++ b/lib.c
@@ -252,9 +252,11 @@ val rplaca(val cons, val new_car)
{
switch (type(cons)) {
case CONS:
- return set(mkloc(cons->c.car, cons), new_car);
+ set(mkloc(cons->c.car, cons), new_car);
+ return cons;
case LCONS:
- return set(mkloc(cons->lc.car, cons), new_car);
+ set(mkloc(cons->lc.car, cons), new_car);
+ return cons;
default:
type_mismatch(lit("~s is not a cons"), cons, nao);
}
@@ -265,9 +267,11 @@ val rplacd(val cons, val new_cdr)
{
switch (type(cons)) {
case CONS:
- return set(mkloc(cons->c.cdr, cons), new_cdr);
+ set(mkloc(cons->c.cdr, cons), new_cdr);
+ return cons;
case LCONS:
- return set(mkloc(cons->lc.cdr, cons), new_cdr);
+ set(mkloc(cons->lc.cdr, cons), new_cdr);
+ return cons;
default:
type_mismatch(lit("~s is not a cons"), cons, nao);
}
@@ -950,7 +954,7 @@ static val rem_lazy_rec(val obj, val list, val env, val func);
static val rem_lazy_func(val env, val lcons)
{
cons_bind (pred, list, env);
- return rplacd(lcons, rem_lazy_rec(pred, list, env, lcons_fun(lcons)));
+ return cdr(rplacd(lcons, rem_lazy_rec(pred, list, env, lcons_fun(lcons))));
}
static val rem_lazy_rec(val pred, val list, val env, val func)
@@ -5165,8 +5169,8 @@ static void obj_init(void)
rplacd(gethash_c(user_package->pk.symhash, nil_string, nulloc), nil);
/* t can't be interned, because intern needs t in order to do its job. */
- t = rplacd(gethash_c(user_package->pk.symhash,
- lit("t"), nulloc), make_sym(lit("t")));
+ t = cdr(rplacd(gethash_c(user_package->pk.symhash,
+ lit("t"), nulloc), make_sym(lit("t"))));
set(mkloc(t->s.package, t), user_package);
null_s = intern(lit("null"), user_package);
diff --git a/txr.1 b/txr.1
index b54ce957..2a62737d 100644
--- a/txr.1
+++ b/txr.1
@@ -7102,6 +7102,11 @@ is the same as the more generic (set (car x) y), and likewise
It is an error if <cons> is not a cons or lazy cons. In particular,
whereas (car nil) is correct, (rplaca nil ...) is erroneous.
+The rplaca and rplacd functions return <cons>.
+
+Note: TXR versions 89 and earlier, these functions returned the new value.
+The behavior was undocumented.
+
.SS Functions second, third, fourth, fifth and sixth
.TP