How do Clojure futures and promises differ?

Answering in Clojure terms, here are some examples from Sean Devlin’s screencast: (def a-promise (promise)) (deliver a-promise :fred) (def f (future (some-sexp))) (deref f) Note that in the promise you are explicitly delivering a value that you select in a later computation (:fred in this case). The future, on the other hand, is being consumed … Read more

Common programming mistakes for Clojure developers to avoid [closed]

Literal Octals At one point I was reading in a matrix which used leading zeros to maintain proper rows and columns. Mathematically this is correct, since leading zero obviously don’t alter the underlying value. Attempts to define a var with this matrix, however, would fail mysteriously with: java.lang.NumberFormatException: Invalid number: 08 which totally baffled me. … 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

Clojure vs other Lisps [closed]

My personal list of reasons for preferring Clojure to other Lisps (p.s. I still think all Lisps are great!): Runs on the JVM – hence gets automatic access to the fantastic engineering in the JVM itself (advanced garbage collection algorithms, HotSpot JIT optimisation etc.) Very good Java interoperability – provides compatibility with the huge range … Read more

What’s the “big idea” behind compojure routes?

Compojure explained (to some degree) NB. I am working with Compojure 0.4.1 (here’s the 0.4.1 release commit on GitHub). Why? At the very top of compojure/core.clj, there’s this helpful summary of Compojure’s purpose: A concise syntax for generating Ring handlers. On a superficial level, that’s all there is to the “why” question. To go a … Read more

What is Clojure useful for? [closed]

I’ve used Clojure for: Scraping web pages Shell scripts Building websites Playing around with OpenGL Writing async webservers HTML Templating Running parallel tasks (fetching multiple URLs and process in parallel) Playing around with real time audio Simulations That’s the practical / fun stuff. But Clojure has plenty of theoretical depth as well. Ideas that will … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)