picrin/contrib/50.destructuring-bind/lambda.scm

25 lines
680 B
Scheme
Raw Normal View History

2015-07-08 13:18:56 -04:00
(define-library (picrin destructuring-bind)
(import (picrin base)
(picrin macro))
(define-syntax (destructuring-bind formal value . body)
(cond
2016-02-06 09:15:53 -05:00
((identifier? formal)
2015-07-08 13:18:56 -04:00
#`(let ((#,formal #,value))
#,@body))
((pair? formal)
#`(let ((value #,value))
(destructuring-bind #,(car formal) (car value)
(destructuring-bind #,(cdr formal) (cdr value)
#,@body))))
((vector? formal)
;; TODO
(error "fixme"))
(else
#`(if (equal? #,value '#,formal)
(begin
#,@body)
(error "match failure" #,value '#,formal)))))
(export destructuring-bind))