Clojure programming language

Updated: 2020-04-07 by Pradeep Gowda.

Clojure is a Lisp that runs on the Java Virtual Machine (JVM).

Learning resourses

Courseware

Presentations

Clojure like languages

IDE and infrastructure

REPL

online playgrounds

Getting started with Lighttable

Via

Basic instructions. I use cmd for the shortcuts below, substitute ctrl on non-mac platforms.

  1. Install Leiningen http://leiningen.org/ you do not need to install clojure, lein will grab clojure for you.
  2. lein new playground from the command line to create a ‘playground’ project
  3. Open Light Table
  4. ctrl-space woto for “Toggle Workspace tree”
  5. Add the playground project folder you just created
  6. cmd-o core.clj to open the main clojure file for the project
  7. On an empty line type (+ 1 1) and hit cmd-enter

Things will grind away for a while as all the dependencies are downloaded and the JVM starts up. Get a cup of coffee or something. Eventually you’ll see a green 2 show up.

You can then type anything in the tutorial and hit cmd-enter to evaluate it or cmd-shift-enter to evaluate the entire file. Think of the file as a shell with an editable history instead of something you’d want to commit to source control.

Documentation is searchable via ctrl-shift-d or moving your cursor on top of a function name and hitting ctrl-d. Autocomplete is available on tab, you can jump to definition with cmd-. and back with cmd-,

TODO: Explore CIDER + AC(autocomplete) + ritz.

Applications

Libraries

Spec

the biggest win from spec has been with parsing. This completely changes how you’d write a library that takes a data structure and parses it into something meaningful (for example, what hiccup does for html or what honeysql does for sql). In the past, this required a lot of very ugly parsing code and manual error-checking. With spec, you write specs and call s/conform. If it failed, you get a nice error, especially if you pair it with expound. If it succeeded, you get a destructured value that is really easy to pull data out of. I’ve done this in a half dozen different libraries and i’m pretty sure i wouldn’t have even written them without spec.

Mallimalli and specmonstahspecmonstah are my favourite Clojure(Script) libraries built on top of Clojure Spec.

Clojure books

The second chapter, Idioms, provides specific, syntactic advice for writing Clojure which is clean and readable.

The third chapter, Indirection, looks at how code can made simpler and more robust through separation.

The final chapter, Composition, explores how the constituent pieces of our code can be combined into an effective whole.

Clojurescript books

Experience reports and discussions

Articles

Talks and presentations

Tips and tricks

Cool projects / Read Code

Visualization / Notebook

Web development

Big data

Blogs

ClojureScript

Graal

Web development

PCP

alekcz/pcp: PCP: Clojure Processor – Like drugs but better

Just use it like PHP on a webserver (say nginx):

    #new pcp config => change .php to .clj
    index index.clj index.html index.htm;
    #new pcp config => change .php to .clj
    location ~ \.clj$ {
        #default nginx config on digital ocean lemp image
        #include snippets/fastcgi-php.conf;
        #fastcgi_pass unix:/run/php/php7.0-fpm.sock;

        include scgi_params;
        scgi_intercept_errors on;
        scgi_pass   127.0.0.1:9000;
    }

PCP has following libraries built in:

(require  '[cheshire.core :as json]
      '[clostache.parser :as clo]
      '[selmer.parser :as parser]
      '[selmer.filters :as filters]
      '[clj-http.lite.client :as client]
      '[next.jdbc :as jdbc]
      '[honeysql.core :as sql]
      '[honeysql.helpers :as helpers]
      '[postal.core :as email]
      '[clojurewerkz.scrypt.core :as sc])

Learning Journal

clojure -Sdeps '{:deps 
    {hello-clojure 
        {:git/url "https://gist.github.com/athos/b68b15b08efedffaf14d8c020b125202" 
        :sha "1c9a05106171f97f9b8e8ac8f58c7bd8dbe021f9"}}}'
    -m hello-clojure        

See also: lisp, scheme.