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

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Tue Jun 28 17:23:34 EDT 2011

Syntax info is stored in the cons.   ... constructs a new cons. The elements are the same so they have the same syntax locations. But the cons is new, so it has no syntax location information.

Your method is one way to avoid this, but there are others.  But I'm dictating to my wife (I'm driving) so I can't go into them right now.

xoxo
Jay's personal secretary

iPhoneから送信

On 2011/06/28, at 14:51, Danny Yoo <dyoo at cs.wpi.edu> wrote:

> 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
> conditions.
> 
> 
> 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.
> _________________________________________________
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users



Posted on the users mailing list.