Last active
December 21, 2015 08:59
-
-
Save shirok/6281700 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 util.match) | |
(use srfi-1) | |
(define-macro (def proc . xs) | |
(let loop ([xs xs] [clauses '()]) | |
(if (null? xs) | |
`(define ,proc (match-lambda* ,@(reverse clauses))) | |
(receive (args rest) (break ($ eq? '-> $) xs) | |
(loop (cddr rest) | |
(cons (list args (cadr rest)) clauses)))))) | |
#| | |
(def m | |
f () -> () | |
f (hd . tl) -> (cons (f hd) (m f tl))) | |
(m (cut + 1 <>) '(1 2 3 4)) ;=> (2 3 4 5) | |
|# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment