Mathias
Mathias

Reputation: 233

Racket macro with infinite number of arguments

I would like a macro that can take any number of arguments and return a list of each argument, like this:

(TEST first second third)
=> '(first second third)

Upvotes: 2

Views: 651

Answers (2)

Óscar López
Óscar López

Reputation: 236004

Here's another way, using define-syntax:

(define-syntax TEST
  (syntax-rules ()
    ((_ . lst) 'lst)))

Of course you can quote the expression directly, it really isn't necessary to use a macro here:

'(first second third)

Upvotes: 4

uselpa
uselpa

Reputation: 18917

Like so?

(define-syntax-rule (TEST . lst)
  (quote lst))

(TEST first second third)
=> '(first second third)

or simply

(define-syntax-rule (TEST . lst)
  'lst)

Upvotes: 5

Related Questions