Skip to content

Instantly share code, notes, and snippets.

@jafingerhut
Last active October 2, 2019 19:44
Show Gist options
  • Save jafingerhut/2da2c48a9d26844a3d8a8db3c9891f87 to your computer and use it in GitHub Desktop.
Save jafingerhut/2da2c48a9d26844a3d8a8db3c9891f87 to your computer and use it in GitHub Desktop.
Creating a cljs REPL from terminal using deps.edn and clj command
;; Save this file as deps.edn in some directory that doesn't already
;; have such a file.
;; You must have the following installed for the command below to have
;; a chance of working:
;; + A JDK, e.g. from AdoptOpenJDK web site: https://adoptopenjdk.net
;; + Clojure CLI tools. Install instructions here:
;; https://clojure.org/guides/getting_started
;; + Node.js JavaScript runtime environment. Some prepackaged ways to
;; install:
;; + Ubuntu 18.04 Linux: `sudo apt-get install nodejs`
;; + macOS
;; + plus Homebrew: `brew install node`
;; + plus MacPorts: `sudo port install nodejs10`. You can see
;; other versions available via the command `port list | grep
;; nodejs`.
;; clj -m cljs.main --repl-env node
;; If that is successful, you should eventually see output like this:
;; $ clj -m cljs.main --repl-env node
;; ClojureScript 1.10.520
;; cljs.user=>
;; At the REPL, I could evaluate these forms without errors:
;; (require '[clojure.core.matrix :as m])
;; (require '[clojure.core.matrix.dataset :as d])
;; cljs.user=> (m/identity-matrix 2)
;; [[1 0] [0 1]]
;; cljs.user=> (m/shape [[2 3 4] [5 6 7]])
;; [2 3]
;; cljs.user=> (m/mmul (m/array [[2 2] [3 3]]) (m/array [[4 4] [5 5]]))
;; [[18 18] [27 27]]
;; I have not tried using the core.matrix library any more extensively
;; than that, yet.
;; In the directory where you run this, a .cpcache directory will be
;; created by clj to cache information about dependencies.
;; It will also write files to a $HOME/.cljs/.aot_cache directory,
;; which appears to be a cache of ClojureScript source files and their
;; corresponding compiled-to-JavaScript results, from the
;; ClojureScript compiler.
;; As most JDK things do, it will download JAR files and save them to
;; your $HOME/.m2 directory.
{:deps {org.clojure/clojurescript {:mvn/version "1.10.520"}
net.mikera/core.matrix {:mvn/version "0.62.0"}}
:aliases
{:socket {:jvm-opts ["-XX:-OmitStackTraceInFastThrow"
"-Dclojure.server.repl={:port,50505,:accept,cljs.server.node/repl}"]}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment