Hi , i am pleased to introduce defun <https://github.com/killme2008/defun>:
a beautiful macro to define clojure functions with pattern match.
Some examples:
(defun say-hi
([:dennis] "Hi,good morning, dennis.")
([:catty] "Hi, catty, what time is it?")
([:green] "Hi,green, what a good day!")
([other] (str "Say hi to " other)))
(say-hi :dennis)
;; "Hi,good morning, dennis."
(say-hi :catty)
;; "Hi, catty, what time is it?"
(say-hi :green)
;; "Hi,green, what a good day!"
(say-hi "someone")
;; "Say hi to someone"
Recursive function? It's all right:
(defun count-down
([0] (println "Reach zero!"))
([n] (println n)
(recur (dec n))))
(defun fib
([0] 0)
([1] 1)
([n] (+ (fib (- n 1)) (fib (- n 2)))))
Guard functions? it's all right:
(defun valid-geopoint?
([(_ :guard #(and (> % -180) (< % 180)))
(_ :guard #(and (> % -90) (< % 90)))] true)
([_ _] false))
(valid-geopoint? 30 30)
;; true
(valid-geopoint? -181 30)
;; false
It's really cool,all the magic are from core.match, much more details
please see
https://github.com/killme2008/defun
--
庄晓丹
Email: [email protected] [email protected]
Site: http://fnil.net
Twitter: @killme2008
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.