On 09/28/2016 02:33 PM, 'William J. Bowman' via Racket Users wrote:
I recently ran into a problem that took me hours to diagnose.
It turns out that a `#:with` clause in a syntax-parse was not matching, but I 
would never have guessed
that from the error message I got.

Here is a simplified example:

  (define-syntax-rule (my-fancy-macro syn ...) (begin syn ...))

  (define-syntax (my-let syn)
    (syntax-parse syn
      #:literals (begin)
      [(_ ([x e] ...) body)
       #:with (lambda (y ...) (begin e^ ...))
       (local-expand #`(lambda (x ...) (my-fancy-macro e ...)) 'expression null)
       #`((lambda (y ...) body) e^ ...)]))

  (my-let ([x 5]) x)
  ; /tmp/test.rkt:29.0: my-let: expected the identifier `begin'
  ;   at: quote
  ;   in: (my-let ((x 5)) x)
  ; Context: ....

It's not clear where "quote" comes from; it doesn't appear in the syntax I've 
written
down or any of the patterns I've written, so it's totally useless for debugging.

The `quote` is coming from the local expansion:

   (lambda (x) (begin 5))  -->*  (lambda (x) '5)

because of begin-splicing and explicit quoting of constants (via #%datum).

Would something like `debug-syntax-parse!` extended with Alex's proposal (https://github.com/racket/racket/issues/1377) for more debugging information have helped?

Meanwhile, you can also fall back to printf debugging using #:do side-clauses.


It gets even worse when I remember I forgot to declare `lambda' as a literal:

  (define-syntax (my-let syn)
    (syntax-parse syn
      #:literals (lambda begin)
      [(_ ([x e] ...) body)
       #:with (lambda (y ...) (begin e^ ...))
       (local-expand #`(lambda (x ...) (my-fancy-macro e ...)) 'expression null)
       #`((lambda (y ...) body) e^ ...)]))

  (my-let ([x 5]) x)
  ; /tmp/test.rkt:29.0: my-let: expected the identifier `lambda
  ;   at: lambda
  ;   in: (my-let ((x 5)) x)
  ; Context: ....

So, we expected to see identifier that is there?
That's a strange error.
I'm not sure if this one is related, but it came up in the same debugging 
session.

Is there anything to be done about these error message?

I'll see if I can squeeze it into the error message that the identifier was expected to have a different binding.

Ryan

--
You received this message because you are subscribed to the Google Groups "Racket 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to