diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2014-10-31 07:17:20 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2014-10-31 07:17:20 -0700 |
commit | e313ceee48d860d3ee9591298c9ac1630096610b (patch) | |
tree | 0dc09b716d4e84be264824417c44f95c2daf45b7 | |
parent | 484dd64d138a1ae977af05193036d3fe46220b2c (diff) | |
download | txr-e313ceee48d860d3ee9591298c9ac1630096610b.tar.gz txr-e313ceee48d860d3ee9591298c9ac1630096610b.tar.bz2 txr-e313ceee48d860d3ee9591298c9ac1630096610b.zip |
New macros tb and tc.
* eval.c (me_tb, me_tc): New static functions.
(eval_init): Registered tb and tc macros.
* txr.1: Documented tb and tc.
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | eval.c | 30 | ||||
-rw-r--r-- | txr.1 | 72 |
3 files changed, 111 insertions, 0 deletions
@@ -1,3 +1,12 @@ +2014-10-31 Kaz Kylheku <kaz@kylheku.com> + + New macros tb and tc. + + * eval.c (me_tb, me_tc): New static functions. + (eval_init): Registered tb and tc macros. + + * txr.1: Documented tb and tc. + 2014-10-30 Kaz Kylheku <kaz@kylheku.com> * lib.c (chk_grow_vec): New function. @@ -2595,6 +2595,34 @@ static val me_case(val form, val menv) cons(cond_s, condpairs), nao); } +static val me_tb(val form, val menv) +{ + val opsym = pop(&form); + val pat = pop(&form); + val body = form; + val args = gensym(lit("args-")); + + (void) opsym; + (void) menv; + + return list(lambda_s, args, + cons(tree_bind_s, cons(pat, cons(args, body))), nao); +} + +static val me_tc(val form, val menv) +{ + val opsym = pop(&form); + val cases = form; + val args = gensym(lit("args-")); + + (void) opsym; + (void) menv; + + return list(lambda_s, args, + cons(tree_case_s, cons(args, cases)), nao); +} + + static val expand_catch_clause(val form, val menv) { val sym = first(form); @@ -3506,6 +3534,8 @@ void eval_init(void) reg_mac(caseq_s, me_case); reg_mac(caseql_s, me_case); reg_mac(casequal_s, me_case); + reg_mac(intern(lit("tb"), user_package), me_tb); + reg_mac(intern(lit("tc"), user_package), me_tc); reg_fun(cons_s, func_n2(cons)); reg_fun(intern(lit("make-lazy-cons"), user_package), func_n1(make_lazy_cons)); @@ -25306,6 +25306,78 @@ is important: even more so than the order of cases in a or .codn caseql . +.coNP Macro @ tb +.synb +.mets (tb < macro-style-params << form *) +.syne +.desc +The +.code tb +macro is similar to the +.code lambda +operator but its argument binding is based on a macro-style parameter list. +The name is an abbreviation of +.codn tree-bind . + +A +.code tb +form evaluates to a function which takes a variable number of +arguments. + +When that function is called, those arguments are taken as a list object which +is matched against +.meta macro-style-params +as if by +.metn tree-bind . +If the match is successful, then the parameters are bound to the +corresponding elements from the argument structure and each successive +.meta form +is evaluated an environment in which those bindings are visible. +The value of the last +.meta form +is the return value of the function. If there are no forms, +the function's return value is +.codn nil . + +The following equivalence holds, where +.code args +should be understood to be a globally unique symbol: + +.cblk + (tb pattern body ...) <--> (lambda (. args) + (tree-bind pattern args body ...)) +.cble + +.coNP Macro @ tc +.synb +.mets (tc >> {( macro-style-params << form *)}*) +.syne +.desc +The +.code tc +macro produces an anonymous function whose behavior is closely +based on the +.code tree-case +operator. Its name is an abbreviation of +.codn tree-case . + +The anonymous function takes a variable number of arguments. +Its argument list is taken to be the value macro is tested +against the multiple pattern clauses of an implicit +.codn tree-bind . +The return value of the function is that of the implied +.codn tree-bind . + +The following equivalence holds, where +.code args +should be understood to be a globally unique symbol: + +.cblk + (tc clause1 clause2 ...) <--> (lambda (. args) + (tree-bind args + clause1 clause2 ...)) +.cble + .SS* Debugging Functions .coNP Functions source-loc and source-loc-str .synb |