Interactive Clojure Notebook: gorilla-repl
“gorilla-repl” is a tool that lets you have notebook-style interface in a web browser, instead of linear command line interface in terminal.
gorilla-repl home page is http://gorilla-repl.org/index.html
install
You'll need to install Leiningen first. Clojure Leiningen Tutorial
Just run the lein install shell script.
Then, run
# create a new Clojure project dir structure named xyz lein new app xyz
Then, in dir “xyz”, you'll find a file project.clj
. Add this line:
:plugins [ [lein-gorilla "0.3.3"] ]
start gorilla
Then, run lein gorilla
. (cd to the directory first if not already)
Then, you'll see this:
~/git/xyz $ lein gorilla Gorilla-REPL: 0.3.3 Started nREPL server on port 38714 Running at http://localhost:42034/worksheet.html . Ctrl+C to exit.
Now, go to your browser
http://localhost:42034/worksheet.html
You'll see this:
now, press Shift+Enter to evaluate the current cell.
now, you can start to type Clojure expressions.
now, try (+ 3 4)
Note: gorilla-repl is basically a notebook interface to Clojure (similar to Mathematica). So, everything you type should still mostly be valid Clojure code.
gorilla-repl does add some nice things. Try 3 + 4
. Note: you need the spaces.
Now, try a plot.
(use 'gorilla-plot.core)
(list-plot [1 2 3 4 5 6 7])
You can edit and eval any cell.
Gorilla-REPL Keyboard Shortcuts
The following are for Linux and Microsoft Windows. For Mac, use Alt intead.
- Shift+Enter
- eval current cell.
- Alt+Shift+Enter
- eval all cells.
- Ctrl+Space or Alt+g Alt+a
- show completion for current word.
- Alt+g Alt+c
- lookup documentation of the symbol under cursor, in http://clojuredocs.org/ site.
working with cells
- Alt+g Alt+x
- delete current cell.
- Alt+g Alt+m
- make current cell inactive as notes. You can type anything, such as title, instruction, explanations, description, notes etc. Markdown format is supported.
- Alt+g Alt+j
- change current cell to active.
- Alt+g Alt+n
- create a new cell below.
- Alt+g Alt+b
- create a new cell above.
- Alt+g Alt+u
- move current cell up.
- Alt+g Alt+d
- move current cell down.
worksheet
- Alt+g Alt+l
- load worksheet.
- Alt+g Alt+s
- save worksheet.
- Alt+g Alt+e
- save worksheet with new filename.
- Alt+g Alt+g
- show all keyboard shortcuts. (or Click on the menu icon on upper right corner).
Save Worksheet
You can save a worksheet.
Alt+g Alt+s → save current file to disk.
It'll be saved at the directory gorilla-repl is started.
gorilla-repl worksheets should end in .clj
or .cljw
gorilla-repl worksheets are Clojure files with magic comments.
viewing Clojure doc
first, import it
(use 'clojure.repl)
then in gorilla worksheet, you can type (doc list)
see its doc, or (source list)
Important gorilla-repl Startup Options
# start with a specified port lein gorilla :port 8999
:port number
:ip ip_address
:nrepl-port number