在标题里说这个问题有点困难。
(define-syntax func
(syntax-rules ()
((func a b c (d e) ...) (cond ((and (not (empty? d)) (not (empty? e))) (+ d e))
)
)
)
)如果有人调用(func a b c (1 1) (2 2)),我希望它将所有的d和e放在一起。
syntax: missing ellipsis with pattern variable in template in: d
如果它甚至没有给我那个错误,我甚至不确定它是否会把它们全部加在一起。如果没有提供d和e,我也希望它能做其他的事情,所以我把它放在cond中。
谢谢。
编辑:
(define-syntax func
(syntax-rules ()
((func a b c (d e) ...)
(cond
((and
(not (empty? d))
(not (empty? e)))
(+ d e))))))发布于 2016-10-10 18:36:34
模式something ...将匹配零或多个元素。因此,在您的模式中,(func a b c)将与规则匹配。
如果一个模式在模式中有省略,那么它需要扩展中的省略。例如:
(define-syntax test
(syntax-rules ()
((_ a b ...)
(if a (begin #t b ...) #f))))
(test 1) ; ==> #t
(test 1 2) ; ==> 2
(test #f 2) ; ==> #fhttps://stackoverflow.com/questions/39963532
复制相似问题