Clojure XML Parsing

Suppose you have the following xml to parse in your file: <high-node> <low-node>my text</low-node> </high-node> you load clojure.xml: user=> (use ‘clojure.xml) when parsed, the xml will have the following structure: {:tag :high-node, :attrs nil, :content [{:tag :low-node, :attrs nil, :content [“my text”]}]} and then you can seq over the content of the file to get … Read more

How can I get the methods of a Java class from Clojure?

[EDIT 2] Per M Smith’s comment below, this accomplishes the same but provides sorting by method name and only returns methods: (print-table (sort-by :name (filter :exception-types (:members (r/reflect “foo”))))) [/EDIT 2] [EDIT] My original answer refers to Clojure 1.2, but things have changed with Clojure 1.3. This works without any reliance on Clojure’s contrib libraries … Read more

Let vs. Binding in Clojure

let creates a lexically scoped immutable alias for some value. binding creates a dynamically scoped binding for some Var. Dynamic binding means that the code inside your binding form and any code which that code calls (even if not in the local lexical scope) will see the new binding. Given: user> (def ^:dynamic x 0) … Read more

Clojure: rest vs. next

As the page you linked described, next is stricter than (the new behaviour of) rest because it needs to evaluate the structure of the lazy cons to know whether to return nil or a seq. rest on the other hand always returns a seq, so nothing needs to be evaluated until you actually use the … Read more