You can't do this using syntax-rules
, but you can do it using syntax-case
, by using a guard that uses free-identifier=?
. Here's an example:
(define-syntax (remove-id stx)
(syntax-case stx ()
((_ head ())
#''())
((_ head (next tail ...)) (free-identifier=? #'head #'next)
#'(remove-id head (tail ...)))
((_ head (next tail ...))
#'(cons 'next (remove-id head (tail ...))))))
> (remove-id foo (foo bar baz qux foo bar))
; => (bar baz qux bar)
But of course, if you're going to use syntax-case
, there's a much simpler way to implement your quote-unique
(this implementation uses Racket's custom hashtables):
(require (for-syntax racket/dict))
(define-syntax (quote-unique stx)
(define (id-dict ids)
(foldl (lambda (id d)
(dict-set d id #t))
(make-immutable-custom-hash free-identifier=? (compose eq-hash-code syntax-e))
(syntax-e ids)))
(syntax-case stx ()
((_ ids ...)
(with-syntax ((unique (dict-keys (id-dict #'(ids ...)))))
#''unique))))