prop:rename-transformer caching results in macro expander

20 views
Skip to first unread message

Leif Andersen

unread,
Dec 14, 2015, 3:37:55 PM12/14/15
to racke...@googlegroups.com
Hello,

I am trying to use a struct that is both mutable, and has
prop:rename-transformer, to create a mutable rename transformer. I am
able to update the value in the struct, and that update gets reflected
properly when I do `syntax-local-value/immediate`, but
`syntax-local-value` seems to keep around the previous definition.

Is prop:rename-transformer or syntax-local-value supposed to cache its
result, or would this be a bug?

My code so far is here: http://pasterack.org/pastes/41342

```
#lang racket

(define-syntax string1 "hello")
(define-syntax string2 "world")

(begin-for-syntax
(struct string-box (str)
#:mutable
#:property prop:rename-transformer
(lambda (inst)
(if (string-box-str inst)
#'string1
#'string2))))
(define-syntax (string-lookup stx)
(syntax-case stx ()
[(_ id)
#`'#,(syntax-local-value #'id)]))
(define-syntax (string-set! stx)
(syntax-case stx ()
[(_ box value)
(begin
(define-values (x y) (syntax-local-value/immediate #'box))
(set-string-box-str! x #'value)
#'(void))]))

(define-syntax current-str (string-box #t))
(string-lookup current-str)
(string-set! current-str #f)
(string-lookup current-str)
```

Thank you for your help.

~Leif Andersen

Matthew Flatt

unread,
Dec 14, 2015, 4:09:17 PM12/14/15
to Leif Andersen, racke...@googlegroups.com
The main problem is that you need to attach the 'not-free-identifier=?
property to the syntax object produced by your rename transformer:

(begin-for-syntax
(struct string-box (str)
#:mutable
#:property prop:rename-transformer
(lambda (inst)
(syntax-property
(if (string-box-str inst)
#'string1
#'string2)
'not-free-identifier=?
#t))))

Otherwise, `current-str` is created as an alias to the binding of the
initial result from `(string-box #t)`. That binding alias effectively
overrides rename transformer.


A second problem is that you want `(syntax-e #'value)` instead of just
`#'value`.
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-dev+...@googlegroups.com.
> To post to this group, send email to racke...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-dev/CAAVaeEBxrRT1soNDP5xmrJnaYwfc49qUA
> N9P44qEqudggjUmgA%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

Leif Andersen

unread,
Dec 14, 2015, 4:50:49 PM12/14/15
to Matthew Flatt, racket-dev
That worked. Thank you Matthew.

~Leif Andersen
> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-dev/566f2ffc.4e09620a.205ee.fffff772SMTPIN_ADDED_MISSING%40gmr-mx.google.com.
Reply all
Reply to author
Forward
0 new messages