> On 29 Jan 2017, at 11:21, Ben Greenman <benjaminlgreen...@gmail.com> wrote:
> 
> 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

Nice, thanks! I wasn’t aware of that. so macros are expanded in the order that 
the reader reads them, not in so called evaluation order.

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