-
-
Save greghendershott/4059716 to your computer and use it in GitHub Desktop.
#lang racket | |
;; This has a nested with-syntax | |
(define-syntax (good stx) | |
(syntax-case stx () | |
[(_ x ...) | |
(with-syntax ([(y ...) #'(x ...)]) | |
(with-syntax ([(z ...) (generate-temporaries #'(y ...))]) | |
#'(let ([z x] ...) | |
#t)))])) | |
;; I thought I could avoid that using with-syntax | |
(define-syntax (not-ok stx) | |
(syntax-case stx () | |
[(_ x ...) | |
(with-syntax* ([(y ...) #'(x ...)] | |
[(z ...) (generate-temporaries #'(y ...))]) | |
#'(let ([z x] ...) | |
#t))])) | |
;; But it complains: | |
;; ...: ellipses not allowed as an expression in: ... | |
;; highlighting the ... in (y ...) | |
;; Is this a bug, or an undocumented as-intended limitation of with-syntax*? |
I'm not so sure this is a bug. with-syntax* needs to be required at compile time: it's not a part of the standard 'racket' language: it lives in racket/syntax. Try:
lang racket/base
(require (for-syntax racket/base
racket/syntax))
;; I thought I could avoid that using with-syntax
(define-syntax (not-ok stx)
(syntax-case stx ()
[(_ x ...)
(with-syntax* ([(y ...) #'(x ...)]
[(z ...) (generate-temporaries #'(y ...))])
#'(let ([z x] ...)
#t))]))
The way I debugged this: I used the macro stepper, disabled macro hiding, and watched as the expander thought that 'with-syntax_' was a plain old function that it didn't know about yet: it introduced #%app's, and then started walking through the "operands", and finally raised an error when it hit the ellipsis. As soon as I saw it was treating with-syntax_ as plain old function, that caught my attention.
I think this is a bug.