Skip to content

Instantly share code, notes, and snippets.

@shirok
Last active December 21, 2015 08:59
Show Gist options
  • Save shirok/6281700 to your computer and use it in GitHub Desktop.
Save shirok/6281700 to your computer and use it in GitHub Desktop.
(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