2014-05-18 33 views
0

在Guile或使用SRFI-46时,可能会出现如Specifying a Custom Ellipsis Identifier所示。但是在SISC或“纯方案”R5RS中可能吗?如何创建一个在SISC/Scheme中生成另一个宏的宏?

我知道这是可能的,但不使用省略号,但如果我需要使用像省略号这样的内部省略号?

(define-syntax define-quotation-macros 
    (syntax-rules() 
    ((_ (macro-name head-symbol) ...) 
    (begin (define-syntax macro-name 
       (syntax-rules :::() 
       ((_ x :::) 
       (quote (head-symbol x :::))))) 
      ...)))) 
(define-quotation-macros (quote-a a) (quote-b b) (quote-c c)) 
(quote-a 1 2 3) ⇒ (a 1 2 3) 

回答

1

在SISC使用的宏膨胀,psyntax,支持不同方式做的内椭圆形,通过使用...宏。您可以通过应用...宏每个内部椭圆要使用这样写:

(define-syntax define-quotation-macros 
    (syntax-rules() 
    ((_ (macro-name head-symbol) ...) 
    (begin (define-syntax macro-name 
       (syntax-rules() 
       ((_ x (... ...)) 
       '(head-symbol x (... ...))))) 
      ...)))) 

,或者你可以将它应用到外形,所有的椭圆内都应该是内:

(define-syntax define-quotation-macros 
    (syntax-rules() 
    ((_ (macro-name head-symbol) ...) 
    (begin (define-syntax macro-name 
       (... (syntax-rules() 
        ((_ x ...) 
         '(head-symbol x ...))))) 
      ...))))