[racket] unhygienic macro on purpose?

From: Todd O'Bryan (toddobryan at gmail.com)
Date: Tue Aug 3 08:02:47 EDT 2010

I'm trying to write a macro to provide functional mutators for the
teaching languages. Here's the main construct:

(define-syntax (define-struct-with-setters stx)
  (syntax-case stx ()
    [(_ id fields)
     (let ([field-names (syntax->list #'fields)])
           (define-struct id fields #:transparent)
           #,@(for/list ([f field-names])
              (setter #'id field-names f))))]))

Everything works, mostly. The problem is that this uses define-struct
from #lang racket instead of the teaching language where the macro is
invoked. (Thus, the #:transparent argument.) I know there's some way
to get define-struct evaluated in the environment of the macro's use
instead of its definition, but I can't get it to work.

Is there a way to fix it?


Posted on the users mailing list.