Felipe
Felipe

Reputation: 17181

How to create a macro that generates another macro in SISC / Scheme?

In Guile or using SRFI-46 it is possible like shown in Specifying a Custom Ellipsis Identifier. But is it possible in SISC or "pure scheme" R5RS?

I know it is possible without using ellipsis, but what if I need to use inner ellipsis like the example bellow?

(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)

Upvotes: 0

Views: 89

Answers (1)

C. K. Young
C. K. Young

Reputation: 223003

The macro expander used in SISC, psyntax, supports a different way to do inner ellipses, by using the ... macro. You can write this by applying the ... macro to each inner ellipses you want to use:

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

or you can apply it to an outer form where all the ellipses within are supposed to be inner:

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

Upvotes: 1

Related Questions