[racket] Using ... in a syntax pattern destroys location information?

From: Danny Yoo (dyoo at cs.wpi.edu)
Date: Tue Jun 28 16:51:54 EDT 2011

I was working with a few friends, and we came across the following
behavior: simple usage of the syntax pattern matching system doesn't
seem to preserve the syntax location of syntax objects under certain

Here's an example to demonstrate:

#lang racket

(define x (datum->syntax #f 'hello (list 'my-source 3 3 18 5)))
(define y (datum->syntax #f 'world (list 'my-source 3 9 24 5)))

(define a-bigger-syntax #`(module foo racket/base (#%module-begin #,x #,y)))

(define a-reconstructed-syntax
  (syntax-case a-bigger-syntax ()
    [(module name language (a-modbeg body ...))
     #'(module name language (a-modbeg body ...))]))

When we inspect the syntax locations in a-reconstructed-syntax, we see
funkiness associated with the locations of the body elements.

We've isolated the issue down to the use of ...; if we do the
following, things look slightly better, but the location of the
'world' is still messed up.

(define another-reconstructed-syntax
  (syntax-case a-bigger-syntax ()
    [(module name language (a-modbeg . body))
     #'(module name language (a-modbeg . body))]))

I guess I'm trying to say: I don't understand the behavior of syntax
and syntax-case, with regards to how they preserve the source
locations of the matched sub-elements.

Posted on the users mailing list.