summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--eval.c7
-rw-r--r--txr.115
3 files changed, 29 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 590119d6..45624ab8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2014-03-21 Kaz Kylheku <kaz@kylheku.com>
+
+ * eval.c (me_when): New static function.
+ (eval_init): Register "when" macro.
+
+ * txr.1: Documented when macro.
+
2014-03-19 Kaz Kylheku <kaz@kylheku.com>
Second round of bugfixing on the theme of the previous commit.
diff --git a/eval.c b/eval.c
index b0213253..ba287c5c 100644
--- a/eval.c
+++ b/eval.c
@@ -2021,6 +2021,12 @@ static val me_pprof(val form, val menv)
nao);
}
+static val me_when(val form, val menv)
+{
+ (void) menv;
+ return cons(cond_s, cons(rest(form), nil));
+}
+
val expand_forms(val form, val menv)
{
if (atom(form)) {
@@ -3179,6 +3185,7 @@ void eval_init(void)
reg_mac(qquote_s, me_qquote);
reg_mac(sys_qquote_s, me_qquote);
reg_mac(intern(lit("pprof"), user_package), me_pprof);
+ reg_mac(intern(lit("when"), user_package), me_when);
reg_fun(cons_s, func_n2(cons));
reg_fun(intern(lit("make-lazy-cons"), user_package), func_n1(make_lazy_cons));
diff --git a/txr.1 b/txr.1
index 4dbc7dbe..0849ad05 100644
--- a/txr.1
+++ b/txr.1
@@ -5580,6 +5580,21 @@ If the first form of a group yields nil, then processing continues with the
next group, if any. If all form groups yield nil, then the cond form yields
nil. This holds in the case that the syntax is empty: (cond) yields nil.
+.SS Macro when
+
+.TP
+Syntax:
+
+ (when <expression> {<form>}*)
+
+.TP
+Description:
+
+The when macro operator evaluates <expression>. If <expression> yields
+true, and there are additiona forms, then each <form> is evaluated.
+The value of the last form is becomes the result value of the when form.
+If there are no forms, then the result is nil.
+
.SS Operator/function if
.TP