Created
July 29, 2010 13:48
-
-
Save tana/498164 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
(use srfi-1) | |
(use util.match) | |
(define (split-patterns l) | |
(let* ((rest (car l)) (pats (cadr l)) (pos (list-index (pa$ eq? '->) rest))) | |
(if (not (eq? pos #f)) | |
(split-patterns (cons (drop rest (+ pos 2)) | |
(list (append pats (list (take rest (+ pos 2))))))) | |
pats))) | |
(define-macro (def name . pats) | |
`(define ,name | |
(match-lambda* | |
,@(map | |
(lambda (clause) | |
(receive (pat body) | |
(split-at clause (list-index (pa$ eq? '->) clause)) | |
`(,pat ,(cadr body)))) | |
(split-patterns `(,pats ())))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment