Cool, if only that macro could expand to function which detects in runtime
if one of argument which being matched is seq or vec and call proper routine
which is applying :seq or leaving matching expression as for random access.
This is just higher level automation, it doesn't breake core functio
A very basic version that works:
(defmacro defmatch [name & patterns]
(let [bindings (take (count (first patterns))
(repeatedly #(gensym "ocr-")))]
`(defn ~name [~@bindings]
(match [~@bindings]
~@patterns
A bit more work is required to m
Playing with it I've come up with this code which Clojure barfs on:
(defn- n-gensyms [n]
(take n (repeatedly gensym)))
(defmacro defmatch [name & patterns]
(let [bindings# ~(n-gensyms (count (first (patterns]
`(defn ~name bindings#
(match bindings#)
~@patterns)))
Hello folks,
I've been playing a little with core.match and thought it would be fun to
make a defmatch macro:
https://gist.github.com/1258277
The super simple macro I came up with enables this:
(defmacro defmatch [name bindings & patterns]
`(defn ~name ~bindings
(match