Rename support for derived names to DrRacket

When a macro creates bindings using derived names, they are not considered to be references to the original name (which is the expected behavior). However, renaming does not work with derived names.

Here's a simple example of a macro:

(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 does not rename get-foo

on the third line.

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

      

For example, is there some syntax property that I can bind to foo

and get-foo

to provide a rename helper (which could create a list of original / renamed pairs)?

As a last resort, I could use a fixed convention and use a read extension to actually expand get-foo

to (get foo)

, although I'm not sure if that would even work.

+3


source to share


2 answers


This is a very good question.

I got a tip from the author DrRacket. The binding sub-range 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

+3


source


As far as I know, identifiers follow the Lisp tradition that goes back entirely to 1958, in which symbols are atomic and are not treated as if they were constituent parts. Therefore, Racket has no information about the foo

inside get-foo

. He only knows about get-foo

.



0


source







All Articles