Skip to content

Instantly share code, notes, and snippets.

@dmitric
Created February 18, 2011 04:11
Show Gist options
  • Save dmitric/833239 to your computer and use it in GitHub Desktop.
Save dmitric/833239 to your computer and use it in GitHub Desktop.
(defn mark-up [tag-name value]
(str "<" tag-name ">" value "</" tag-name ">"))
(defn xmlify [names fields]
(reduce str (map #(mark-up %1 %2) names fields)))
;;will work, but ugly... makes each html element
(?<- (stdout) [?p ?xml-name ?xml-age ?xml-gender] (age ?p ?a) (gender ?p ?g)(mark-up "name" ?p :> ?xml-name) (mark-up "age" ?a :> ?xml-age)(mark-up "gender" ?g :> ?xml-gender))
;;wont substitute value in for ?var and requires subquery for more than one join
(?<- (stdout) [?p ?xml] (age ?p ?a) (xmlify '("name" "age") '(?p ?a) :> ?xml))
;;; nice way to shell out if need be
(import '(java.io BufferedReader InputStreamReader))
(defn cmd [p] (.. Runtime getRuntime (exec (str p))))
(defn cmdout [o]
(let [r (BufferedReader.
(InputStreamReader.
(.getInputStream o)))]
(dorun (map println (line-seq r)))))
(cmdout (cmd "ls -a"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment