summaryrefslogtreecommitdiffstats
path: root/eval.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-12-22 13:55:09 -0800
committerKaz Kylheku <kaz@kylheku.com>2016-12-22 13:55:09 -0800
commitd64c62ea9236ee63d4b56ba9945bc6e4c3df967f (patch)
tree8ef0dd0554e5d57d08e1be73cc99788587823ef8 /eval.c
parentd9d04630165b65b70feeba43f8ceda8a863d90f5 (diff)
downloadtxr-d64c62ea9236ee63d4b56ba9945bc6e4c3df967f.tar.gz
txr-d64c62ea9236ee63d4b56ba9945bc6e4c3df967f.tar.bz2
txr-d64c62ea9236ee63d4b56ba9945bc6e4c3df967f.zip
Last var may be omitted in iflet/whenlet/condlet.
* eval.c (me_iflet_whenlet): Allow the last binding to be (init-form) instead of (sym init-form), for situations in which sym is never used. * txr.1: Documented.
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/eval.c b/eval.c
index caa3c501..c4cd24cf 100644
--- a/eval.c
+++ b/eval.c
@@ -3430,16 +3430,30 @@ static val me_iflet_whenlet(val form, val env)
return apply_frob_args(list(if3(sym == iflet_s, if_s, when_s),
lets, args, nao));
} else {
- val lastlet = last(lets, nil);
+ val lastlet_cons = last(lets, nil);
+ val lastlet = car(lastlet_cons);
if (nilp(lastlet))
eval_error(form, lit("~s: empty binding list"), sym, nao);
+ if (!consp(lastlet))
+ eval_error(form, lit("~s: bad binding syntax ~s"), sym, lastlet, nao);
+ {
+ val var = car(lastlet);
+
+ if (!cdr(lastlet)) {
+ if (symbolp(var) && bindable(var))
+ eval_warn(form, lit("~s: ~s is init-form here, not new variable"),
+ sym, var, nao);
+ push(gensym(nil), &lastlet);
+ lets = append2(butlast(lets, nil), cons(lastlet, nil));
+ }
+ }
return list(let_star_s, lets,
cons(if3(sym == iflet_s, if_s, when_s),
- cons(car(car(lastlet)), args)), nao);
+ cons(car(lastlet), args)), nao);
}
}