I have a macro that extends the racket syntax, and at some point accepts a sequence of bog standard racket expressions. This looks something like this, the relevant syntax variable being body
:
(syntax-parse stx
[(_ some-id:id
body:expr ...+)
This macro generates a racket class with a generated method like so:
#'(<class stuff>
(define/public (some-id some-formal-parameter)
body ...)
As I said the body
is plain racket code, except for one expression that can be used exclusively in the body, for example:
(define-syntax-rule (tweet identifier value)
(send this publish-tweet (quote identifier) value))
But this does not allow me to use some-formal-parameter
because it is not defined. Is there some proper way in which I can define something that can exclusively be used in the body, and can still bind to variables in the context after expansion? Maybe via a splicing syntax class? Reusability is a big bonus, since this "type of body" may exists in multiple (similar) macros.
Some code for testing:
#lang racket
(require (for-syntax syntax/parse))
(define-syntax (define-something stx)
(syntax-parse stx
[(_ some-id:id
body:expr ...+)
#'(define some-id
(new
(class object%
(super-new)
(define/public (displ arg)
(displayln arg))
(define/public (tick some-formal-parameter)
body ...))))]))
(define-syntax-rule (tweet value)
(send this displ value))
(define-something derp
(define a 'not-derp)
(tweet a))
(send derp tick 'derp)