Created
February 18, 2011 04:11
-
-
Save dmitric/833239 to your computer and use it in GitHub Desktop.
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
(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