On Sun, Jan 29, 2017 at 10:06:30AM -0800, Matias Eyzaguirre wrote:
> Hullo all,
> 
> I'm messing around with syntax properties to try to get a feel for them, but 
> in one of my tests they aren't behaving the way I would expect them to.
> 
> In my example the output is #f 1 #f, when I would have thought it would be #f 
> 1 2. Why is the third result #f and not 2?
> 
> 
> #lang racket
> 
> (define-syntax (annotate stx)
>   (syntax-case stx ()
>     [(_ val) ; read
>      (or (syntax-property #'val 'annotation) #'#f)]
>     [(_ val ann) ; write
>      (syntax-property #'val 'annotation #'ann #t)]))
> 
> (annotate 4) ; -> #f
> 
> (annotate 1 6) ; -> 1
> 
> (annotate (annotate 4 2)) ; -> 2
Because annotation is a macro, it receives the syntax of the input, not the 
value of the input.
The outer call to annotate receives the value #'(annotate 4 2), which has no 
syntax property, and
hence returns #f.

Your code is roughly like writing:
(syntax-property #'4 'annotation) ; -> #f

(syntax-property #'1 'annotation 6 #t) ; -> #'1

(syntax-property #'(syntax-property #'4 'annotation 2 #t)) ; -> #f

Try this instead:

(define annotated (syntax-property #'4 'annotation 2))
(syntax-property annotated 'annotation)

--
William J. Bowman

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Attachment: signature.asc
Description: PGP signature

Reply via email to