The third result is #f because in the third example, stx is `(annotate
(annotate 4 2))`. So the first pattern matches and `val` is the syntax
`(annotate 4 2)`.

You can get a "strict" evaluation order by using `local-expand` inside the
`annotate` macro. For example:

#lang racket

(define-syntax (annotate stx)
  (syntax-case stx ()
   [(_ val) ; read
   (or (syntax-property (local-expand #'val 'expression #f) 'annotation)
#'#f)]
   [(_ val ann) ; write
   (syntax-property #'val 'annotation #'ann #t)]))

(annotate 4) ;; ==> #f
(annotate 1 6) ;; ==> 1
(annotate (annotate 4 2)) ;; ==> 2


On Sun, Jan 29, 2017 at 1:06 PM, Matias Eyzaguirre <mat...@fortlogic.net>
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
>
> --
> 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.
>

-- 
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.

Reply via email to