Search This Blog

Thursday, December 2, 2021

A test program

#!/usr/bin/env clojure

;; It looks like clojure has become a full citizen of Debian

;; In emacs, a syntax highlighted program can be converted to html with htmlize-buffer, and then if
;; you top and tail that and copy it to blogger it comes up nicely. And this seems to still be
;; working after all this time

;; So here is my first published clojure program for a while...

;; If you're using Debian 11, you can run it by installing clojure with
;; $ sudo apt install clojure

;; saving this file as test.clj

;; and then in a terminal window making the file executable
;; $ chmod +x test.clj
;; and then running it
;; $ ./test.clj

(println "hello")

(defn factorial [n]
  (if (< n 1) 1
      (* n (factorial (- n 1)))))

(println '(factorial 10) (factorial 10))

;; If all is working then you should see something like
;; $ ./test.clj
;; hello
;; (factorial 10) 3628800

2 comments:

  1. Having trouble following...

    So, Clojure is available in Debian 11 stable via apt? Did previous versions of Debian not have clojure available?

    P.S. What version of Clojure does Debian 11 come with?

    Thank you!

    ReplyDelete
  2. Clojure's available through apt, it kind of always was but it used to be quite out of date so I always had to install the latest version by hand. I didn't need to bother this time since the apt version is 1.10.2 which is pretty current.

    More importantly from my point of view, and this is new since last time I looked, you can just write a program as a script in the usual manner with a shebang, like you can with most other languages that are happy citizens of unix.

    There's a start up delay of about 2 seconds, but that's the only thing that makes you think you're not just using a nice normal language.

    ReplyDelete

Followers