This is the mail archive of the
kawa@sources.redhat.com
mailing list for the Kawa project.
Re: Use define-simple-class in macros?
- From: Per Bothner <per at bothner dot com>
- To: dominique dot boucher at nuecho dot com
- Cc: "'Kawa List'" <kawa at sources dot redhat dot com>
- Date: Tue, 21 Jun 2005 13:13:46 -0700
- Subject: Re: Use define-simple-class in macros?
- References: <200506211915.j5LJFVf4012910@bergman.nuecho.ad>
Dominique Boucher wrote:
At least, your problem reminded me of a problem with macros and Kawa
classes. It does not seem possible to write a hygienic macro that uses
(this):
#|kawa:1|# (define-syntax with-self
(syntax-rules ()
((_ body ...)
(let ((self (this)))
body ...))))
#|kawa:2|# (define-simple-class <A> (<Object>)
((allo)
(with-self
(format #t "Allo: ~S~%" self))))
Unless I'm missing something, this is *supposed* to not work. The whole
point of macro hygiene is that the "actual macro parameter" 'body' is
not in the scope of the 'self' defined by the 'let'. Think of it as
pure lexical scoping: the 'self' in the define-simple-class is not
lexically in the scope of any definition of 'self'.
This handles the hygiene problem:
(define-syntax with-self
(syntax-rules ()
((_ with-self body ...)
(let ((self (this)))
body ...))))
(define-simple-class <A> (<Object>)
((allo)
(with-self self
(format #t "Allo: ~S~%" self))))
Unfortuantely, we get a warning about (this) not inside a class
- because lexically we're not. This should be fixed to search the
"real nesting" rather than the lexical scope. There are various
ways to fix this, but it's not an immediate one-line fix, I think.
--
--Per Bothner
per@bothner.com http://per.bothner.com/