[plt-dev] possible bug in syntax position of dotted syntax
Yes, that's as intended.
In the original `(1 2 3 4)', there isn't a syntax object `(4)'. The
pairs within the syntax-object list `(1 2 3 4)' are plain pairs without
their own location or context. The alternative of wrapping every
internal pair as a syntax object would be expensive, and the extra
information would be used very rarely.
So, when the syntax object `(4)' is synthesized for `d' from the plain
pair extracted from the syntax object `(1 2 3 4)', the new syntax
object gets the source location of `(1 2 3 4)'. This approximation is
not always what you want, but it has been a workable compromise between
precise source information and using less memory.
At Fri, 29 Jan 2010 15:14:55 -0700, Jon Rafkind wrote:
> I noticed that when I use a dotted template for syntax-case (and
> syntax-parse) that the dotted element has a syntax-position equivalent
> to the entire expression. Is this expected behavior?
>
> (define (with-syntax-case stx)
> (syntax-case stx ()
> [(a b c . d)
> (begin
> (printf "a is at ~a\n" (syntax-position #'a))
> (printf "b is at ~a\n" (syntax-position #'b))
> (printf "c is at ~a\n" (syntax-position #'c))
> (printf "d is at ~a\n" (syntax-position #'d)))]))
>
> (with-syntax-case #'(1 2 3 4))
>
> ==>
> a is at 695
> b is at 697
> c is at 699
> d is at 694
>
> I would expect `d' to be at position 701 instead of 694.