diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2014-03-21 23:24:40 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2014-03-22 11:52:56 -0700 |
commit | 654a913f119664bce805fb2da94bcee0349ab7fb (patch) | |
tree | da63867f8ec40ab0818851139b2491841027baf4 | |
parent | 3e17fb079dcecebded6e7d8c834b918d9a3b541a (diff) | |
download | txr-654a913f119664bce805fb2da94bcee0349ab7fb.tar.gz txr-654a913f119664bce805fb2da94bcee0349ab7fb.tar.bz2 txr-654a913f119664bce805fb2da94bcee0349ab7fb.zip |
* eval.c (me_when): New static function.
(eval_init): Register "when" macro.
* txr.1: Documented when macro.
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | eval.c | 7 | ||||
-rw-r--r-- | txr.1 | 15 |
3 files changed, 29 insertions, 0 deletions
@@ -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. @@ -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)); @@ -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 |