[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Interaction between syntax-tables and environments
There's been a lot of Common Lisp mail recently about the optional
"environment" argument to MACROEXPAND and related functions, although
environments are not very well explained in the Common Lisp manual. Of
course, I think T's notion of syntax tables is much cleaner, and I was
about to suggest that if they're going to make some changes, they might
do well to consider something like syntax tables. But one nagging problem
we've faced in T is that there *is* an interaction between
macro-expanders and the environment, and it can cause trouble. Short,
grotesque example:
(DEFINE-SYNTAX (KAR X) `(CAR ,X))
(LET ((CAR CDR)) (KAR '(1 2 3))) => (2 3)
The person who defined KAR probably wanted the expanded code to use the
standard CAR, but because macros manipulate S-expressions and not values,
there's nothing to prevent the environment from thwarting his intentions.
Of course, you could write
(DEFINE-SYNTAX (KAR X)
`((*VALUE *STANDARD-ENV* 'CAR) ,X))
but then you lose in efficiency, open-compilability, etc. One way around
this is to extend the rules for evaluation to permit the CAR of a form
to be a procedure (as opposed to a symbol that is bound to a procedure).
(A similar thing is currently implemented for special forms.) If this
were implemented, we could write
(DEFINE-SYNTAX (KAR X) `(,CAR ,X))
or, being very careful,
(DEFINE-SYNTAX (KAR X)
`(,(*VALUE *STANDARD-ENV* 'CAR) ,X))
and avoid the problem. This introduces other problems (e.g., external
representation, compiler), but it might be workable.
Comments? Other suggestions?