Difference between Symbols and Vars in Clojure

There’s a symbol + that you can talk about by quoting it: user=> ‘+ + user=> (class ‘+) clojure.lang.Symbol user=> (resolve ‘+) #’clojure.core/+ So it resolves to #’+, which is a Var: user=> (class #’+) clojure.lang.Var The Var references the function object: user=> (deref #’+) #<core$_PLUS_ clojure.core$_PLUS_@55a7b0bf> user=> @#’+ #<core$_PLUS_ clojure.core$_PLUS_@55a7b0bf> (The @ sign is … Read more

Producer consumer with qualifications

Here’s my take on it. I made a point of only using Clojure data structures to see how that would work out. Note that it would have been perfectly usual and idiomatic to take a blocking queue from the Java toolbox and use it here; the code would be easy to adapt, I think. Update: … Read more

Clojure on Android [closed]

Yes, here is main project I am aware of: https://github.com/remvee/clojurehelloandroid And here is a little tutorial http://riddell.us/ClojureAndAndroidWithEmacsOnUbuntu.html though I would not be surprised if this tutorial is outdated, as it was over a year ago when I played with the code following this tutorial, and remvee’s code has since been updated. EDIT: see the update … Read more

How to list the functions of a namespace?

I normally call (keys (ns-publics ‘foo)) to list Vars exported by the namespace foo; e.g. for clojure.contrib.monads this returns (defmonad censor m-when-not m+write+m maybe-m maybe-t …) (the … stands for quite a lot more). More generally, there’s a bunch of functions whose names start in ns- which list Vars by namespace, with certain additional criteria … Read more

How do I find the index of an item in a vector?

Built-in: user> (def v [“one” “two” “three” “two”]) #’user/v user> (.indexOf v “two”) 1 user> (.indexOf v “foo”) -1 If you want a lazy seq of the indices for all matches: user> (map-indexed vector v) ([0 “one”] [1 “two”] [2 “three”] [3 “two”]) user> (filter #(= “two” (second %)) *1) ([1 “two”] [3 “two”]) user> … Read more