Re: What's up with Scheme macros?
- From: Kent M Pitman <pitman@xxxxxxxxxxx>
- Date: 19 Feb 2008 21:06:29 -0500
[ comp.lang.lisp only; http://www.nhplace.com/kent/PFAQ/cross-posting.html ]
Ron Garret <rNOSPAMon@xxxxxxxxxxx> writes:
I don't understand. Why should:
(let ((x ...))
(defmacro ... () (foo x)))
be any different from:
(let ((x ...))
(defun f () (foo x)))
(defmacro ... () (f ...))
Because the binding has to happen at a known time so the init form
happens at a known time.
One could make a form that has a known time, but one would have to
define the semantics to accommodate ... it doesn't just happen for
free. And the reason they're not defined is mostly that no one was
happy with the various semantics that were discussed.
So, for example, the real issue [and the reason the operator is not
defined this way] is expressed by looking at concrete use cases. A
typical one might be:
When would
(let ((x (print ''a)))
(defmacro foo () x)
(foo))
print (QUOTE A)? At compile time? At load time? Both?
Moreover, why would the compiler know to expand (foo) at all since the
definition of FOO as a macro would not be installed until runtime, if
it were to follow what DEFUN does.
particularly in light of the fact that one can do e.g.:
(progn
'#1=#:f ; Or #:|| to really drive the point home
(let (...)
(defun #1# () (foo x)))
(defmacro ... () (#1# ...)))
I'm going to assume you wrote:
(progn
'#1=#:f ; Or #:|| to really drive the point home
(let ((x ...))
(defun #1# () (foo x)))
(defmacro g () (#1# ...)))
so I can refer to the parts more easily.
I personally would not rely on that macro to work so I don't
know if your claim is correct.
It will work in the same file, but if you ever later do any
macroexpansion of G which you don't then immediately compile but
instead externalize (e.g., by print) to a file for later compilation,
you'll find that when it reloads, the use of the gensym won't be
repatriated correctly. Not that that's your point. It's just a
lurking bug in your program that will survive a long time before being
noticed.
But as to the part about the binding of x, what you should know is
that it's permissible for calls to (g) to warn that f is undefined,
since it doesn't take on a value until runtime [when the defun is
executed], and the compiler doesn't notice that your #:F function (in
the cases where it works at all [1]) has a definition.
[1] = not to be confused with the cases where it doesn't work because
in fact it never gets a definition.
Lisp used to have COMPILER-LET, and no one liked it. But it was much
closer to the semantics you want. In mixed compiled and interpreted
code with special and lexical bindings all about, it created cases
where it was very hard to debug. So we removed it.
.
- Follow-Ups:
- Re: What's up with Scheme macros?
- From: Ron Garret
- Re: What's up with Scheme macros?
- Prev by Date: Re: Printing values of a list of variables
- Next by Date: Re: Openmcl run-program args
- Previous by thread: Re: What's up with Scheme macros?
- Next by thread: Re: What's up with Scheme macros?
- Index(es):
Relevant Pages
|
Loading