3
votes

When a macro produces bindings using derived names, these are not considered references to the original name (which is expected behaviour). However, renaming doesn't work on the derived names.

Here is a simple macro example:

(define-syntax (my-syntax stx)
  (syntax-case stx ()
    [(_ name)
     (with-syntax ([get-name (format-id #'name "get-~a" #'name)])
       #'(begin
           (define name 42)
           (define (get-name) name)))]))

In the code below, renaming foo on the first line to bar with right-click → Rename foo correctly renames foo on the second line, but fails to rename get-foo on the third line.

(my-syntax foo)
foo
(get-foo)

Is there for example some kind of syntax property that can be attached to foo and get-foo to provide a rename-helper (that could produce a list of original / renamed pairs)?

As a last resort, I could use a fixed convention, and use a reader extension to actually expand get-foo to (get foo) early on, although I'm not sure if that would even work.

2

2 Answers

3
votes

This is a very nice question.

I got a tip from the author of DrRacket. The 'sub-range-binders property should do the trick:

http://docs.racket-lang.org/tools/Check_Syntax.html?q=sub-binder#%28idx._%28gentag.28.%28lib._scribblings%2Ftools%2Ftools..scrbl%29%29%29

0
votes

As far as I'm aware, identifiers follow the Lisp tradition that goes all the way back to 1958, in which symbols are atomic, and are not treated as if they had constituent parts. So Racket doesn't have any information about the foo within get-foo. It only knows about get-foo.