Created
April 28, 2011 05:07
-
-
Save ichiban/945835 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
(require :fare-matcher) | |
;; Clojure or ML's function syntax style defun | |
(defmacro defunction (name &body body) | |
(flet ((match-clause (clause) | |
(cons `(list ,@(car clause)) (cdr clause)))) | |
(let ((args (gensym))) | |
`(defun ,name (&rest ,args) | |
(fare-matcher:ematch ,args | |
,@(mapcar #'match-clause body)))))) | |
;; examples | |
(defunction f | |
((:ping) :pong) | |
((:echo x) x)) | |
(f :ping) ; ==> :pong | |
(f :echo "hi") ; ==> "hi" | |
(f 1 2 3) ; ==> raise error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment