[racket] syntax-local-value mystery
Could someone explain why the program below raises a syntax error?
The error goes away if you make either of the following changes:
1. enable errortrace, or
2. change `syntax' to `quote' in the `expand' argument.
;;;;
#lang racket/load
; Change #1
;(require errortrace)
(module t racket
(provide (struct-out src))
(struct src (line col)))
(module r racket
(require (for-syntax 't))
(provide def use)
(define-syntax (def stx)
(syntax-case stx ()
[(_ x)
(identifier? #'x)
#`(define-syntax x
(src #,(syntax-line stx) #,(syntax-column stx)))]))
(define-syntax (use stx)
(syntax-case stx ()
[(_ x)
(identifier? #'x)
(let ([src (syntax-local-value #'x (λ () #f))])
(if src
#`(format "~a at ~a:~a"
'#,(syntax-e #'x)
#,(src-line src)
#,(src-col src))
(raise-syntax-error #f "no def" stx #'x)))])))
(module u racket
(require 'r)
(define-namespace-anchor module-anchor)
(parameterize ([current-namespace (namespace-anchor->namespace
module-anchor)])
(eval #'
; Change #2
;'
(module m racket
(require 'r)
(def x)
(use x)))
(eval '(require 'm))))
(require 'u)