Skip to content

Instantly share code, notes, and snippets.

@greghendershott
Created November 12, 2012 14:28
Show Gist options
  • Save greghendershott/4059716 to your computer and use it in GitHub Desktop.
Save greghendershott/4059716 to your computer and use it in GitHub Desktop.
with-syntax* ?
#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*?
@samth
Copy link

samth commented Nov 12, 2012

I think this is a bug.

@dyoo
Copy link

dyoo commented Nov 12, 2012

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))]))

@dyoo
Copy link

dyoo commented Nov 12, 2012

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment