[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Quasisyntax

This page is part of the web mail archives of SRFI 93 from before July 7th, 2015. The new archives for SRFI 93 contain all messages, not just those from before July 7th, 2015.



Can quasisyntax be written as a macro in terms of syntax-case? I suspect so, but if not, I would urge its inclusion.

With-syntax often forces one to break apart the natural shape of the
output code, and introduce names (such as rest) that would not be necessary otherwise.

Also, I often find myself writing code fragments like this

  (define (helper bindings body)
    (with-syntax ((bindings bindings)  ; !!
                  (body     body))     ; !!
       (syntax (let bindings body)))

This is bothersome, when quasisyntax instead allows

  (define (helper bindings body)
    (quasisyntax (let #,bindings #, body)))

Also compare

  (define-syntax let-in-order
    (lambda (form)
      (syntax-case form ()
        ((_ ((i e) ...) e0 e1 ...)
         (let f ((ies (syntax ((i e) ...)))
                 (its '()))
           (syntax-case ies ()
             (()            (with-syntax ((its its))
                              (syntax (let its e0 e1 ...))))
             (((i e) . ies) (with-syntax ((rest (f (syntax ies)
                                                   (cons (syntax (i t)) its))))
                              (syntax (let ((t e)) rest))))))))))

with the following, which I find easier to write and read, since now the macro
can follow the structure of the output without the order inversions
required above.

  (define-syntax let-in-order
    (lambda (form)
      (syntax-case form ()
        ((_ ((i e) ...) e0 e1 ...)
         (let f ((ies (syntax ((i e) ...)))
                 (its (syntax ())))
           (syntax-case ies ()
             (()            (quasisyntax (let #,its e0 e1 ...)))
             (((i e) . ies) (quasisyntax
                             (let ((t e))
                               #,(f (syntax ies)
                                    (quasisyntax ((i t) #,@its))))))))))))

Regards
Andre