I have a macro that creates transformer bindings at phases 0 and 1:

(define-syntax (f stx)
  (with-syntax ([name (cadr (syntax-e stx))])
    #'(begin
        (define-syntax name (syntax-id-rules () [_ 1]))
        (begin-for-syntax (define-syntax name (syntax-id-rules () [_
2]))))))

Normally, this works fine. I have syntax transformers bound at both phases
that can resolve "name" with syntax-local-value.

In an expression context, the phase-0 transformer binding can be
overridden temporarily with let-syntax:

(cons
 x (let-syntax
       ([x (syntax-id-rules () [_ 'one])]
        [y (λ (stx) (datum->syntax stx (syntax-local-value #'x)))])
     (list x y)))

This produces '(1 one #<set!-transformer>). With syntax-local-eval instead
of syntax-local-value, it produces '(1 one 2).

Because "f" produces begin-for-syntax, it only works in a module or
top-level evaluation context:

(let () (f x) x)

/tmp/g.rkt:10:8: begin-for-syntax: not in a definition context
  in: (begin-for-syntax (define-syntax x (syntax-id-rules () (_ 2))))

Is there a way to override temporarily the phase-1 transformer binding as
well?

Eric

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