Yes, this did the trick! I needed to add datum->syntax to the identifiers 
in BOTH macros. In my initial attempt I only added it to the defining macro.

More importantly, I now understand why I needed to do it this way. I plan 
to eventually refactor it to pass the identifier in directly instead of as 
a string, which will hopefully simplify things. This will work for now 
though.

Thanks to everyone. I'm continually impressed by the helpfulness and 
patience of this community.

-- Jonathan

On Tuesday, May 28, 2019 at 10:26:38 PM UTC-4, Matthew Butterick wrote:
>
>
> On May 28, 2019, at 7:11 AM, Jonathan Simpson <jjsi...@gmail.com 
> <javascript:>> wrote:
>
> Both the function definition and function calls are created by similar 
> looking macros which pass strings as the function name. I've now taken 
> steps to break hygiene in the defining macro, but the calling macro just 
> converts the string to a symbol. It's invocation looks something like this:
>
> (query
>    (line (offset 0) (type "use") "tga-image"))
>  
> Perhaps they aren't referring to the same binding. Maybe I need a 
> datum->syntax in this macro as well. I don't have access to the code at the 
> moment, so I can't try it, but does this make sense?
>
> If this is the case then I can probably fix it by modifying the other 
> macro as well, but modifying the lexer to emit symbols instead of strings 
> seems like the best approach.
>
>
>
> Here's an example of two macros that both make an identifier out of 
> "tga-image": the first defines a function called `tga-image`, and the 
> second calls it. Notice that the same syntax-context-switching fandango is 
> needed in both cases to ensure that both `tga-image` ids are placed inside 
> the same syntax context, so that the first one binds the second. (As 
> someone pointed out earlier, you could also use `format-id` for this, which 
> is shorthand for the same operation)
>
>
> #lang racket
>
> (define-syntax (definer-macro stx)
>   (syntax-case stx ()
>     [(_ magic-name)
>      (with-syntax ([name (datum->syntax #'magic-name (string->symbol 
> (syntax->datum #'magic-name)))])
>        #'(define (name x) x))]))
>
> (definer-macro "tga-image")
>
> (define-syntax (caller-macro stx)
>   (syntax-case stx ()
>     [(_ magic-name arg)
>      (with-syntax ([name (datum->syntax #'magic-name (string->symbol 
> (syntax->datum #'magic-name)))])
>        #'(name arg))]))
>
> (caller-macro "tga-image" 42)
>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/4b2801cf-ba7b-4af9-b453-7f37bb8bb120%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to