This is the mail archive of the kawa@sources.redhat.com mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Use define-simple-class in macros?


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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]