[plt-scheme] Macro-expansion-time structs
If you want the my-box struct bound at the module level, you can
create another module, use define-struct normally, then import it for
syntax. Or you can use define-values-for-syntax like this (which
won't get the struct's syntax binding, but will get anything else you
need):
#lang scheme/base
(require (for-syntax scheme/base))
(provide test)
(define-values-for-syntax (make-my-box my-box-val my-box?)
(let ()
(define-struct my-box (val))
(values make-my-box my-box-val my-box?)))
(define-syntax test
(lambda (stx)
#`#,(my-box-val (make-my-box 2))))
On Sat, Oct 11, 2008 at 11:22 PM, Henk Boom <lunarc.lists at gmail.com> wrote:
> 2008/10/11 Carl Eastlund <cce at ccs.neu.edu>:
>> You've defined the struct in the runtime environment. You need to
>> define it in the transformer environment if you want transformers to
>> use it. You might accomplish that like this (though this makes a
>> local definition other transformers won't be able to use):
>>
>> #lang scheme/base
>>
>> (require (for-syntax scheme/base))
>>
>> (provide test)
>>
>> (define-syntax test
>> (let ()
>> (define-struct my-box (val))
>> (lambda (stx)
>> #`#,(my-box-val (make-my-box 2)))))
>
> I see. It's a pity that (begin-for-syntax (define-struct . . .)) doesn't work.
>
> Thanks for the info!
> Henk