Created
February 4, 2012 12:44
-
-
Save mhayashi1120/1737630 to your computer and use it in GitHub Desktop.
srfi cond
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmacro srfi-cond (&rest clauses) | |
(reduce | |
(lambda (clause res) | |
(let ((test (car clause))) | |
(cond | |
((eq (cadr clause) '=>) | |
(unless (= (length clause) 3) | |
(error "Malformed `srfi-cond' test => expr")) | |
(let ((v (make-symbol "v"))) | |
`(let ((,v ,test)) | |
(if ,v (,(caddr clause) ,v) ,res)))) | |
((eq (caddr clause) '=>) ; srfi-61 | |
(unless (= (length clause) 4) | |
(error "Malformed `srfi-cond' test guard => expr")) | |
(let ((v1 (make-symbol "v1"))) | |
`(let ((,v1 ,test)) | |
(if (and ,v1 (,(cadr clause) ,v1)) | |
(,(cadddr clause) ,v1) | |
,res)))) | |
(t | |
`(if ,test | |
(progn ,@(cdr clause)) | |
,res))))) | |
clauses | |
:from-end t | |
:initial-value nil)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment