[racket] help about a macro that uses a struct define with "make-struct-type"

From: Maurizio Giordano (maurizio.giorda at gmail.com)
Date: Fri Jul 29 10:57:16 EDT 2011

Hi Mattias,

On Fri, 2011-07-29 at 09:39 -0400, Matthias Felleisen wrote:
> On Jul 29, 2011, at 8:35 AM, Maurizio Giordano wrote:
> 
> > (require (for syntax multiset))   ;; import mset? for macro
> > 
> > (define-syntax (mm stx)
> >   (syntax-case stx ()                
> >        [(_ input ...)
> >         (let* ((l1 (syntax '(input ...)))
> >                (l2 '(input ...)))
> >           (map (lambda (x) (print-type x)) l2)   ; assume print-type is
> > imported for syntax
> >           (datum->syntax stx `(map (lambda (x) (print-type x)) ,l1)
> > stx))])) 
> 
> 
> Are you sure you don't just want to do something like this: 
> 
> 
> (define-syntax (mm stx)
>   (syntax-case stx ()                
>        [(_ input ...)
>         (let* ((l1 (syntax '(input ...)))
>                (l2 '(input ...)))
>           (map (lambda (x) (print-type x)) l2)   ; assume print-type is imported for syntax
>           #'(begin (print-type 'input) ...))]))
> 
> As for your l2, you are just quoting the symbol 'input here. So either this isn't really your macro or you sketched the output 
The macro I have reported is merely an example trying to reproduce the
problem I have in the "real" macro I am trying to implement.
If you remember my last post and discussion, you may figure out why I am
using "(datum->syntax stx `(... (unquote ...))" instead of your 
"(syntax (begin ...))" proposal... you can find all the boring details
in my last thread of discussion. 
 
> Your question isn't clear. 
You are right! I try to clarify my point...
The problem is in the "(map (lambda ... l2)" expression, not in the
syntax the macro produces. 
It is ok when I reference "l1" in the line:
"(datum->syntax stx `(map (lambda (x) (print-type x)) ,l1)"
In fact, the struct "<...>" is recognized correctly in l1 as a "mset"
type. 
It is not in the "(map (lambda ... l2)". For some reason (I bet you
know) the same struct "<...>" IS NOT recognized as a "mset" in the map.
I suppose the input list (l2), when parsed, is stripped out of some
information about user defined (not-prefab) struct. But more likely I am
simply using the macro in a wrong way. 

Thank you for your prompt answer.
Cheers,

Maurizio.




Posted on the users mailing list.