(define-syntax my-class
(syntax-rules ()
[(my-class <class-name> (<attr> ...)
(method (bigger-x other) (> x (other 'x))))
(define (<class-name> <attr> ...)
(lambda (msg)
(cond [(equal? msg (quote <attr>)) <attr>] ...
[(equal? msg 'bigger-x) (lambda (other) (> x (other 'x)))]
[else "Unrecognized message!"])))]))
This is not a good template. But it's good for explaining the syntax of define-syntax
. I am confusing why there is only 1 method in the 4th line. Isn't the quote <attr>
in the expression [(equal? msg (quote <attr>)) <attr>]
also a method? Their structures are quite similar.