diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2025-04-08 21:48:33 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2025-04-08 21:48:33 -0700 |
commit | c1306d943aa9c19d6bbccc1a5c72cddb5af7e564 (patch) | |
tree | 6298d8b68e800653568f4d18cfa3878e93ddb696 | |
parent | 8cc7b9ee27b400ba752f11042f727d68a2ef1dc8 (diff) | |
download | txr-c1306d943aa9c19d6bbccc1a5c72cddb5af7e564.tar.gz txr-c1306d943aa9c19d6bbccc1a5c72cddb5af7e564.tar.bz2 txr-c1306d943aa9c19d6bbccc1a5c72cddb5af7e564.zip |
expand-hook: process DWIM brackets forms.
It turns out we need this for infix.
* eval.c (do_expand): Call the expand hook for
forms headed by the dwim operator, passing that
operator symbol as the type indicator.
* txr.1: Document this and also that the
expand hook doesn't receive symbol macros.
-rw-r--r-- | eval.c | 20 | ||||
-rw-r--r-- | txr.1 | 19 |
2 files changed, 27 insertions, 12 deletions
@@ -5362,12 +5362,22 @@ again: } else if (sym == symacrolet_s) { return expand_symacrolet(form, menv); } else if (sym == dwim_s) { - val args = rest(form); - val args_ex = expand_forms_lisp1(dot_to_apply(args, t), menv); + val eh = expand_hook; + if (eh) { + val eform = funcall3(eh, form, menv, dwim_s); + if (eform != form) { + form = rlcp_tree(eform, form); + goto again; + } + } + { + val args = rest(form); + val args_ex = expand_forms_lisp1(dot_to_apply(args, t), menv); - if (args == args_ex) - return form; - return rlcp(cons(sym, args_ex), form); + if (args == args_ex) + return form; + return rlcp(cons(sym, args_ex), form); + } } else if (sym == switch_s) { return expand_switch(form, menv); } else if (!macro && (macro = lookup_mac(menv, sym))) { @@ -44021,11 +44021,13 @@ a function which takes three arguments: .mono .meti (lambda >> ( form < env << type-keyword ) ...) .onom -Whenever the macro expander encounters the invocation of a symbol macro, -macro, function, or invalid form, it calls the function stored in +Whenever the macro expander encounters the invocation of a macro, +macro, function, DWIM brackets form, or an invalid form, it calls the function +stored in .code *expand-hook* if that variable isn't .codn nil . +The hook is not invoked for symbol macro forms. If the function returns an expression other than .metn form , @@ -44054,9 +44056,10 @@ and others in that category. The .meta type-keyword -argument takes on one of three values: +argument takes on one of four values: .codn :fun , -.code :macro +.codn :macro , +.code dwim or .codn nil . If the value is @@ -44070,8 +44073,10 @@ If the value is .codn :macro , then .meta form -is a macro invocation: if it is a symbol, then it is a symbol macro form, -otherwise an ordinary macro form. +is a macro invocation. If the value is +.codn dwim , +it is a bracket form: a compound form headed by the same symbol +.codn dwim . If .meta type-keyword is @@ -54018,7 +54023,7 @@ atoms, considering them to be the tokens of infix syntax. The .code ifx macro establishes an expansion hook as if by binding the variable -.codn *expander-hook* . +.codn *expand-hook* . Whenever the expansion hook transforms a form, the expression's constituent forms are then recursively visited, and subject to automatic infix expansion. |