summaryrefslogtreecommitdiffstats
path: root/eval.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-12-18 20:50:07 -0800
committerKaz Kylheku <kaz@kylheku.com>2015-12-18 20:50:07 -0800
commitddb0330c904fac025a6f50219937b204c4c880c7 (patch)
treedd1096793bf0fa30fdb683523e1a9a7edb1a7d70 /eval.c
parentf0228c233a9b295c828dc4023f84b092eb8bee51 (diff)
downloadtxr-ddb0330c904fac025a6f50219937b204c4c880c7.tar.gz
txr-ddb0330c904fac025a6f50219937b204c4c880c7.tar.bz2
txr-ddb0330c904fac025a6f50219937b204c4c880c7.zip
New condlet macro; small change to iflet/whenlet.
* eval.c (me_iflet_whenlet): Allow the test form to be an atomic expression instead of bindings. This allows iflet to be used as the sole target construct of condlet, while allowing condlet to have a fallback clause with t. It also means that an empty list of bindings is allowed (since it is the atom nil). * lisplib.c (ifa_set_entries): Add "condlet" to the autoload names for the ifa module. That's where we are adding condlet. * share/txr/stdlib/ifa.tl (sys:if-to-cond): New macro expander helper function, generalizing the writing cond-like macros based on if-like operators. (conda): Rewritten using sys:if-to-cond. (condlet): New macro. * txr.1: Documented change in iflet/whenlet. Documented condlet.
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/eval.c b/eval.c
index c00f6a80..9edc6ae6 100644
--- a/eval.c
+++ b/eval.c
@@ -2961,14 +2961,22 @@ static val me_iflet_whenlet(val form, val env)
val args = form;
val sym = pop(&args);
val lets = pop(&args);
- val lastlet = last(lets);
- if (nilp(lastlet))
- eval_error(form, lit("~s: empty binding list"), sym, nao);
+ if (atom(lets)) {
+ return apply_frob_args(list(if3(sym == iflet_s, if_s, when_s),
+ lets, args, nao));
+ } else {
+ val lastlet = last(lets);
- return list(let_star_s, lets,
- cons(if3(sym == iflet_s, if_s, when_s),
- cons(car(car(lastlet)), args)), nao);
+ if (nilp(lastlet))
+ eval_error(form, lit("~s: empty binding list"), sym, nao);
+
+
+
+ return list(let_star_s, lets,
+ cons(if3(sym == iflet_s, if_s, when_s),
+ cons(car(car(lastlet)), args)), nao);
+ }
}
static val me_dotimes(val form, val env)