From 654a913f119664bce805fb2da94bcee0349ab7fb Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 21 Mar 2014 23:24:40 -0700 Subject: * eval.c (me_when): New static function. (eval_init): Register "when" macro. * txr.1: Documented when macro. --- ChangeLog | 7 +++++++ eval.c | 7 +++++++ txr.1 | 15 +++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/ChangeLog b/ChangeLog index 590119d6..45624ab8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2014-03-21 Kaz Kylheku + + * eval.c (me_when): New static function. + (eval_init): Register "when" macro. + + * txr.1: Documented when macro. + 2014-03-19 Kaz Kylheku 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 {
}*) + +.TP +Description: + +The when macro operator evaluates . If yields +true, and there are additiona forms, then each 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 -- cgit v1.2.3