Beware Clojure's constantly

Posted on Wednesday, 6 January, 2016

I've just [fixed an annoying but harmless issue](https://github.com/yada/ (commit 227f446) in yada which was causing some tests to produce some ugly stack traces.

The issue appeared to be in manifold, but turned out to be a misunderstanding on my part as to the difference between this:

(fn [_] (launch-missiles!))

and this:

(constantly (launch-missiles!))

Before today, I thought these two forms did the same thing: return a function that launches missiles when called.

It turns out that the second form actually launches the missiles. Right away. Whoops!

I'm sure many of us carry this misconceptions with us all the time and usually they're harmless.

The lesson today is: only use constantly with (constant) values!