Created
April 27, 2012 05:03
-
-
Save nathanmarz/2506020 to your computer and use it in GitHub Desktop.
Concise inline operations with Cascalog serfn branch
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 'cascalog.playground) (bootstrap) | |
(require '[clojure.set :as set]) | |
(require '[cascalog.vars :as v]) | |
(defn all-syms [form] | |
(if (coll? form) | |
(reduce (fn [curr elem] (set/union curr (all-syms elem))) | |
#{} | |
form) | |
#{form})) | |
(defmacro imapcatop [& body] | |
(let [used-vars (->> body all-syms (filter symbol?) (filter v/cascalog-var?)) | |
impl `(cascalog.api/mapcatop ~(vec used-vars) ~@body)] | |
`(cascalog.api/predmacro [invars# outvars#] | |
{:pre [(zero? (clojure.core/count invars#))]} | |
[[~impl :<< ~(vec (map str used-vars)) :>> outvars#]] | |
))) | |
(?<- (stdout) [?word ?count] | |
(sentence ?sentence) | |
((imapcatop (.split ?sentence " ")) :> ?word) | |
(c/count ?count)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment