Learning #7: (Hello (Clojure))

So the other day I finished The Little Lisper, a fantastic book that teaches the basic concepts of LISP via a really cool and interactive Q and A style. By the end of the book, you are not only familiar with the basics of Scheme (a LISP dialect), you have essentially implemented a basic interpreter for Scheme, in Scheme.

Anyway, the point of all this is that I still have the yearning to play around with a LISP language. My first thought was Emacs Lisp, however, I never really have taken the time to figure out Emacs, and thus this would require learning two things at once. So, today I decided to check out Clojure. I do not know much about Clojure except that a coworker at Stellar loves it and it utilizes the JVM.


Hello World in Clojure

With Clojure downloaded on my machine, I opened up the REPL… and realized I had not yet installed java on this machine :(

Couldn't find 'java'. Please set JAVA_HOME.

Once Java was installed and I had the Clojure REPL working, I realized very quickly I would want rlwrap in order to access previous REPL commands. And with all this in place, I was ready to rock and roll!

user=> "Hello World!"
"Hello World!"

waving


Fizz Buzz in Clojure

So I got close here, but very quickly got a bit annoyed by the language – this is not something I think I will continue to pursue since Clojure is:

That all being said, this sort of cool language that transpiles to a more common language is very cool. This is the same as Groovy, Scala, Purescript, Typescript, etc… many languages that are actually quite well used. So, I am open to trying this again with another language, but I do not think Clojure is the language for me (to be fair, I do remember having some of the same annoyances with Typescript).

That all being said, here is what I had for Fizz Buzz:

(defn fizz_buzz
  "Classic beginner cs stuff"
  [num]
  (cond
    (= (mod num 15) 0) "FizzBuzz"
    (= (mod num  3) 0) "Fizz"
    (= (mod num  5) 0) "Buzz"
    :else num))

Quite beautiful and simple IMO.

Nod,not too bad