2014-05-18 67 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 ...))))) 
      ...)))) 
相關問題