PasteRack.org
Paste # 341
2020-06-05 17:53:28

Fork as a new paste.

Paste viewed 498 times.


Embed:

`cond' in `if'

   (define-syntax cond
     (syntax-rules (else =>)
       ((cond) (void))
       ;; We use two tokens here to make sure the body cannot be empty.
       ;; Note that there's no `rest' here: `else' is the final condition.
       ((cond (else expr expr* ...))
        (begin expr expr* ...))
       ;; Magic arrow token
       ((cond (test => predicate) rest ...)
        (let ((result test))
          (if result
              (predicate result)
              (cond rest ...))))
       ;; The general condition in the last place, because it can match
       ;; the previous patterns and cause a syntax error.
       ((cond (condition expr expr* ...) rest ...)
        (if condition
            (begin expr expr* ...)
            (cond rest ...)))))