From 67e7e2f4a304e2541c5b12290374d3ddd057e0e8 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 7 Sep 2016 19:16:32 -0700 Subject: Bugfix: issue with expansion of place macros. The expansion of a place macro form should not be subject to a complete macro-expansion (as a regular macro form). Only one round of expansion should be performed, and the results should be re-tried as a place macro. Otherwise an opportunity to expland a place macro will be missed. * share/txr/stdlib/place.tl (sys:pl-expand): Use macroexpand-1 rather than macroexpand. * txr.1: Documentation updated to make the new behavior clear. It's unlikely that anything in the world depends on this, so no backward compatibility switch is being provded to the old behavior. In situations where this makes a difference, the old behavior is likely too wrong to be useful. --- share/txr/stdlib/place.tl | 2 +- txr.1 | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/share/txr/stdlib/place.tl b/share/txr/stdlib/place.tl index 6437ac45..dbae39be 100644 --- a/share/txr/stdlib/place.tl +++ b/share/txr/stdlib/place.tl @@ -139,7 +139,7 @@ (sys:setq place (sys:set-macro-ancestor [pm-expander unex-place] unex-place)))) - (sys:setq place (macroexpand place env)) + (sys:setq place (macroexpand-1 place env)) (when (or (eq place unex-place) (null place) (and (atom place) (not (symbolp place))) diff --git a/txr.1 b/txr.1 index b994ec8c..10e6fde4 100644 --- a/txr.1 +++ b/txr.1 @@ -27430,15 +27430,21 @@ symbol in its leftmost position. Forms which are used as syntactic places are subject to a modified macro-expansion algorithm. If a place macro applies to a place, then it is expanded, otherwise it is taken as-is. Then the place is expanded as a ordinary -macro (possibly a symbol macro). Then the process is repeated from the -beginning, as necessary. Thus, the output of the ordinary macro expansion may -potentially be, again, a place macro. Place macros can expand to other place +macro (possibly a symbol macro), if possible, but only through at most +one round of macro-expansion, as if by +.codn macroexpand-1 . +If the macro-expansion succeeds, its its output might be, again, a place +macro form, and so the process is tried again. Place macros can expand to other place macros or ordinary macros and vice versa. Place macro expansion doesn't use an environment; place macros are in a single global namespace, special to place macros. There are no lexically scoped place macros. Such an effect can be achieved by having a place macro expand to an a form which is the target of a global or local macro, as necessary. +That said, it needs to be made clear that the ordinary macro-expansion +that may be interleaved within place-macro-expansion does take place +in the surrounding macro environment. A place macro can expand to a form +which matches a lexical macro visible at that point. The .code define-place-macro -- cgit v1.2.3