> On May 28, 2019, at 7:11 AM, Jonathan Simpson <jjsim...@gmail.com> 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/2787D491-F179-49DB-8ECB-8302F2D5EF1E%40mbtype.com. For more options, visit https://groups.google.com/d/optout.