November 12, 2016

Lumo

The fastest Clojure REPL in the world – Lumo (by António Nuno Monteiro)

From its announcement:

Lumo is a fast, standalone ClojureScript REPL that runs on Node.js and V8. Thanks to V8’s custom startup snapshots, Lumo starts up instantaneously, making it the fastest Clojure REPL in existence.


Command prompt

Ideally suited to be used instead of e.g. Bash or Perl, for scripts executed from the (Linux in my case) command prompt. Plus Lumo is multi platform!

Example (an HTTP server for IP logging)

#!/usr/bin/env lumo
;;
;; Adapted from: https://mmcgrana.github.io/2011/09/clojurescript-nodejs.html
;;
;; Twitter: @maridonkers | Google+: +MariDonkers | GitHub: maridonkers
;;
 
(def http (js/require "http"))
(def process (js/require "process"))
 
(defn handler [req res]
  (let [dt (.toISOString (js/Date.))
        ip req.connection.remoteAddress]
    (println (str dt " - " ip))
    (.writeHead res 200 (js-obj "Content-Type" "text/html"))
    (.end res (str "<!DOCTYPE html>"
                   "<html>"
                   "<header><title>IP logger</title></header>"
                   "<body><H1>" ip " was logged at " dt "</H1></body>"
                   "</html>\n"))))
 
(let [host (nth (.-argv process) 3)
      port (nth (.-argv process) 4)
      server (.createServer http handler)]
  (.listen server port host)
  (println (str "IP logging server running at http://"
                host ":" port)))

Make the file executable and execute with host and port parameters, e.g. as follows:

./http-ip-logger localhost 8000

And navigate to http://localhost:8000.

Tags: Software Shell Script Computer Linux Clojure ClojureScript Functional