Last active
August 29, 2015 13:56
-
-
Save zeptometer/8885216 to your computer and use it in GitHub Desktop.
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
(import | |
(scheme base) | |
(scheme write) | |
(scheme cxr) | |
(picrin macro)) | |
(define-syntax destructuring-bind | |
(ir-macro-transformer | |
(lambda (form inject compare) | |
(let ((pattern (cadr form)) | |
(value (caddr form)) | |
(body (cdddr form))) | |
(cond ((null? pattern) | |
`(begin ,@body)) | |
((symbol? pattern) | |
`(let ((,pattern ,value)) (begin ,@body))) | |
((pair? pattern) | |
`(let ((evaluated ,value)) | |
(destructuring-bind ,(car pattern) (car evaluated) | |
(destructuring-bind ,(cdr pattern) (cdr evaluated) | |
,@body))))))))) | |
(destructuring-bind (a b . c) '((1 2) 3 4 5) (list a b c)) ; ok | |
(destructuring-bind ((a b) . c) '((1 2) 3 4 5) (list a b c)) ; fail |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment