Search This Blog

Thursday, December 2, 2021

Hello Again World (2nd December 2021) Setting Up Clojure on Debian 11

It's been a while since I've used Clojure, and I've upgraded my system a fair bit since then, so I'm going to try to start again from scratch.

My computer is running latest stable Debian

cat /etc/debian_version

(version 11.1, aka bullseye)

My first instinct is to install via the package manager:

apt search clojure

clojure/stable,now 1.10.2-1 all
  Lisp dialect for the JVM tells me that the latest version is 1.10.3, so the debian version will do.

sudo apt install clojure

Clojure 1.10.2

That seems far too easy, does it work? 

First, can I do hello world at all?

user=> (print "hello")

user=> (defn factorial [n] (if (< n 2) n (* n factorial (- n 1))))


user=> (factorial 10)
Execution error (ClassCastException) at user/factorial (REPL:1).
class user$factorial cannot be cast to class java.lang.Number (user$factorial is in unnamed module of loader clojure.lang.DynamicClassLoader @56ccd751; java.lang.Number is in module java.base of loader 'bootstrap')

Oh my God, what???

.....stares in bewildered disbelief and starts cursing Java and its pointless verbose complexity before seeing the problem and feeling silly...

user=> (defn factorial [n] (if (< n 2) n (* n (factorial (- n 1)))))
user => (factorial 10)

So that looks great, and it was very easy. Things have improved hugely since I last tried this!

I could hope for better error messages, something like 'can't multiply a number by a function' would have been more helpful.



No comments:

Post a Comment