summaryrefslogtreecommitdiffstats
path: root/eval.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-01-06 14:30:18 -0800
committerKaz Kylheku <kaz@kylheku.com>2017-01-06 14:30:18 -0800
commit7efce88113302cae30a6c0af4319b80882abb7db (patch)
tree2bc4379d742768b8f4dbb70b249a76622ec50735 /eval.c
parentad54f9d10165be47b34e6e09d009d115e3808f49 (diff)
downloadtxr-7efce88113302cae30a6c0af4319b80882abb7db.tar.gz
txr-7efce88113302cae30a6c0af4319b80882abb7db.tar.bz2
txr-7efce88113302cae30a6c0af4319b80882abb7db.zip
Allow last var to be omitted in whilet.
* eval.c (me_whilet): insert gensym if last var is missing. Warn if init-form looks like a variable. * txr.1: Documented by copy and paste from iflet.
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/eval.c b/eval.c
index c5151391..319faa5b 100644
--- a/eval.c
+++ b/eval.c
@@ -3466,16 +3466,26 @@ static val me_whilet(val form, val env)
val body = form;
val sym = pop(&body);
val lets = pop(&body);
- val lastlet = last(lets, nil);
+ val lastlet_cons = last(lets, nil);
+ val lastlet = car(lastlet_cons);
val not_done = gensym(lit("not-done"));
- if (nilp(lastlet))
+ if (nilp(lastlet_cons))
eval_error(form, lit("~s: empty binding list"), sym, nao);
+ if (!cdr(lastlet)) {
+ val var = car(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_s, cons(list(not_done, t, nao), nil),
list(while_s, not_done,
list(let_star_s, lets,
- list(if_s, car(car(lastlet)),
+ list(if_s, car(lastlet),
cons(progn_s, body),
list(set_s, not_done, nil, nao), nao), nao), nao), nao);
}