[racket-dev] some surprising behavior with syntax-parameterize and lexical info

From: Danny Yoo (dyoo at cs.wpi.edu)
Date: Fri Apr 6 14:47:40 EDT 2012

>> I suspect that I should be using quote-syntax at this specific point,
>> but I am not completely sure.
> Right. Try replacing ??? with (quote-syntax #,a-placeholder).

I have to admit that I'm still confused.  Here's my example:

#lang racket

(require racket/stxparam racket/splicing)

(define-syntax-parameter current-def #f)

(define-syntax (def stx)
 (syntax-case stx ()
   [(_ (name args ...) body ...)
    (with-syntax ([function-stx stx])
      (syntax/loc stx
        (define (name args ...)
          (splicing-syntax-parameterize ([current-def
            body ...))))]))

(define-syntax (outer stx)
 (syntax-case stx ()
   [(_ id)
    (datum->syntax (syntax-parameter-value #'current-def)
                   (syntax-e #'id))]))

(define x 42)
(def (f x) (* (outer x) x))
(f 2)

Posted on the dev mailing list.