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
11.1
(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
clojure.org tells me that the latest version is 1.10.3, so the debian version will do.
sudo apt install clojure
clojure
Clojure 1.10.2
user=>
That seems far too easy, does it work?
First, can I do hello world at all?
user=> (print "hello")
hellonil
user=> (defn factorial [n] (if (< n 2) n (* n factorial (- n 1))))
#'user/factorial
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
user => (factorial 10)
3628800
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