I’ve been playing around with ClojureScript lately and stumbled upon this little tidbit mentioned by Thomas Boyt on Twitter.
I’m pretty new to ClojureScript and functional programming in general, but since ClojureScript is open source, we can just look up the source code for
enable-console-print! and see that it simply sets
console.log, which makes logging to a browser’s console way easier.
*print-fn* is used by
string-print, which itself is used by many other functions that print to
For example, after enabling console printing, the following functions log to the browser’s console instead of throwing an uncaught error.
(time (sort (reverse (range 42))))
(print (str 42 \newline))
It’s not only more convenient to
println to the browser’s console, it also allows other functions, like the
time function, to log useful information to it.