In Racket or Scheme, is there any way to convert an ellipsis syntax object to a list of syntax objects?

StackOverflow https://stackoverflow.com/questions/18255571

Вопрос

For example:

(syntax-case #'(a b c d) ()
  ((x ...) (list #'x ...))

In the example, (list #'x ...) obviously does not work, but what can I do to output the equivalent of (list #'a #'b #'c #'d)?

Это было полезно?

Решение

Here's one way of doing it:

Welcome to Racket v5.90.0.6.
-> (syntax-case #'(a b c d) ()
     ((x ...) (syntax->list #'(x ...))))
'(#<syntax:5:16 a> #<syntax:5:18 b> #<syntax:5:20 c> #<syntax:5:22 d>)

For more, see the syntax object operations section and the functions exported by syntax/stx.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top