[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Interaction between syntax-tables and environments
- To: Jim Meehan <csi!meehan@UUCP>
- Subject: Re: Interaction between syntax-tables and environments
- From: <ram%YALE-RING@YALE.ARPA>
- Date: Mon ,30 Dec 85 16:43:08 EDT
- Cc: t-discussion@YALE.ARPA
- In-reply-to: Jim Meehan <csi!meehan@UUCP>, Mon, 23 Dec 85 16:45:06 EST
... 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.
Of course there is. Macros, once expanded, call procedures and use other
macros. Since these are gotten to through symbols, there must be an environment
in which these symbols are evaluated. Now you gotta decide whether these
work as in closures, or you want to look up the values at run-time. (The former,
I hope, at least for procedures; possible also for macros (see below).)
(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
This is the most common case, since we love non-dynamic binding and use it
(and expect it) all the time. Why should this work for procedures but not
Comments? Other suggestions?
I'm not sure how easy it is to separate syntax tables and environments (and,
for that matter, read tables). I liked your "workspaces" idea. I think of
syntaxes as being associated with the environments in which they are defined,
in fact almost as if the "value" of a symbol was a syntax, analogous to the
treatment of procedures, and syntax tables were an implementational detail.
The advantage of this is uniformity with the closure idea.
All but the most trivial macros refer to other macros (or special forms) and
to other procedures too, just like procedures do. And just like procedures
are closed at definition time and run in the environment in which they
were defined, I would like my macros to have the symbols they use refer to
the value they have in the definition environment. One way to ensure this
is to use things like
(*value *standard-env* 'CADR) ;(or a special form version of *VALUE)
for standard procedures, just like you use
(t-syntax 'BLOCK) = (syntax-table-entry *standard-syntax-table* 'BLOCK)
for standard macros in T2.9 and T3. But it gets painful to wrap a reference
around every symbol in a macro definition. Just like you can have:
(define (kar x) (car x))
which you can import into another environment and have it work correctly even
if CAR is defined differently there, I would like to be able to do the same with:
(define-syntax (kar x) `(car ,x))
For the same reason, I think making the user wrap (T-SYNTAX ...) around syntax
references is a copout; if KAR refers to a macro, it should be taken from the
definition environment of KAR.
Syntaxes seem ugly in T because they are too much like dynamic binding. Handling
them like procedures should make them a nicer genre of beast to work with.