summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-10-28 05:04:23 -0700
committerKaz Kylheku <kaz@kylheku.com>2015-10-28 05:04:23 -0700
commitd80d25d7bffd8e4dbf8a43870046bc256a12cd66 (patch)
tree16de75112d64de4a9715423e757614fd6b3f89d0
parent58c1299e112e10bcb37ae888f3dbc6d3aa211eeb (diff)
downloadtxr-d80d25d7bffd8e4dbf8a43870046bc256a12cd66.tar.gz
txr-d80d25d7bffd8e4dbf8a43870046bc256a12cd66.tar.bz2
txr-d80d25d7bffd8e4dbf8a43870046bc256a12cd66.zip
Improvement in place macros.
Expansion of places now gives priority to place macros. Moreover, it iterates over place macro and ordinary macro expansion. * share/txr/stdlib/place.tl (sys:trigger-load): Removed. (sys:pl-expand): Rewritten. * txr.1: Documented.
-rw-r--r--share/txr/stdlib/place.tl25
-rw-r--r--txr.128
2 files changed, 40 insertions, 13 deletions
diff --git a/share/txr/stdlib/place.tl b/share/txr/stdlib/place.tl
index b1452225..c60348e6 100644
--- a/share/txr/stdlib/place.tl
+++ b/share/txr/stdlib/place.tl
@@ -126,17 +126,22 @@
^(let ,(zip syms (repeat '((gensym)))) ,*body))
(macro-time
- (defun sys:trigger-load (form)
- (when (consp form) (symbol-function (car form)))
- form)
-
(defun sys:pl-expand (unex-place env)
- (let ((ex-place (sys:expand unex-place env)))
- (sys:trigger-load
- (iflet ((pm-expander [*place-macro* (and (consp ex-place)
- (car ex-place))]))
- [pm-expander ex-place]
- ex-place))))
+ (while t
+ (let ((place unex-place))
+ (let ((pm-expander [*place-macro* (if (consp unex-place)
+ (car unex-place))]))
+ (when pm-expander
+ (sys:setq place [pm-expander unex-place])))
+ (sys:setq place (macroexpand place env))
+ (when (or (eq place unex-place)
+ (null place)
+ (and (atom place) (not (symbolp place)))
+ (and (consp place)
+ (consp unex-place)
+ (eq (car place) (car unex-place))))
+ (return place))
+ (sys:setq unex-place place))))
(defun call-update-expander (getter setter unex-place env body)
(let* ((place (sys:pl-expand unex-place env))
diff --git a/txr.1 b/txr.1
index 9b33de81..b3dd7451 100644
--- a/txr.1
+++ b/txr.1
@@ -24681,9 +24681,31 @@ has the same syntax as
It specifies a macro transformation for a compound form which has the
.meta name
symbol in its leftmost position.
-This macro expansion is applied when such a form is used as a place.
-It is applied after all other expansions, and no other macro-expansions
-are applied afterward.
+
+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
+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.
+
+The
+.code define-place-macro
+form does not cause
+.meta name
+to become
+.code fboundp
+or
+.codn boundp .
+
+There can exist both an ordinary macro and a place macro of the same name;
+moreover, this is potentially useful.
.TP* "Example:"