That makes sense; thank you for your quick reply. It might be
possible to do something like what you describe, but I do have a
little more context that makes this sort of tricky. I’m trying to
not just store identifiers but also store prefab structs containing
identifiers. The issue I’m running into is that embedding prefab
structs in syntax objects seems to “flatten” the contained syntax
objects. For example, if I do something like this:

  (begin-for-syntax
    (struct prefab-box (val) #:prefab)
    (syntax-parse
        (local-expand
         #`(let-syntax ([x (λ (stx)
                             (syntax-property #'(void) 'prop
                                              #,(prefab-box #'add1)))])
             x)
         'expression '())
      #:literals [let-values]
      [(let-values () (let-values () x))
       (prefab-box-val (syntax-property #'x 'prop))]))

The result of this is not the syntax #'add1, but the symbol 'add1.
The reason this happens makes some intuitive sense (though my
understanding of what happens is not precise enough to really explain
it), but it’s not good enough for what I need.

A hacky solution I’ve tried has been to attach the prefab struct
to a piece of “proxy” syntax as a property, like this:

  (define proxy-stx
    (syntax-property #'proxy 'prop (prefab-box #'add1)))

Then I can replace the #,(prefab-box #'add1) with the following:

  (syntax-property #'#,proxy-stx 'prop)

…and I get #'add1 instead of 'add1. This hack seems to cause problems
when it spans multiple modules, though, as I’m discovering. Is there
some other way I can embed a prefab struct in a piece of syntax
without the syntax objects being lost when it is evaluated as an
expression?

> On Oct 25, 2016, at 4:28 PM, Matthew Flatt <mfl...@cs.utah.edu> wrote:
> 
> Putting identifiers in syntax properties causes them to be hidden from
> various scope and module-path-shifting operations. Probably, you're
> seeing the effect of hiding an identifier from path shifting (when an
> expanded module is compiled or when a compiled module is declared and
> instantiated in at a given module path and phase).
> 
> I'd like to have a better story for identifiers in syntax properties.
> Meanwhile, when I have run into this problem, I've usually been able to
> avoid it by putting the identifier in a `quote-syntax` form. That is,
> instead of putting a 'my-info property on some expression
> 
>   e
> 
> I made a macro or other transformer generate
> 
>  (begin
>   (quote-syntax (my-info <info>))
>   e)
> 
> and a traversal of an expression looks for <info> in expressions that
> match that pattern.
> 
> If that strategy doesn't work for you (without major changes to your
> program), then I'm afraid I don't have a better answer at the moment.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to