The REPL - oliyh/learning-clojure GitHub Wiki

The REPL

  1. Start the REPL (Tools > Start Clojure Console)
  2. The user=> prompt you see indicates that you are in the user namespace.

The REPL takes advantage of the dynamic nature of Clojure to provide is a live Clojure environment: 'every feature supported by Clojure is supported at runtime'.

The REPL in Intellij

You're looking at a Clojure file in Intellij. How can you get the code into your REPL to run some of the functions you see?

  1. Start the REPL as per above
  2. Load the file into your REPL (put your mouse cursor in the file and press Ctrl + Shift + L) NB the keyboard shortcut doesn't work for everyone, sort out your key map or else use the menu (Tools > Clojure REPL > Load file to REPL)

You then have some options:

  • Run the function using its fully qualified name e.g.
(learning-clojure.core/hello) ;; "Hello, World!"
  • Use or require the target namespace e.g.
(use 'learning-clojure.core)
(hello) ;; "Hello, World!"
  • Change the current namespace to the target namespace e.g.
(in-ns 'learning-clojure.core)
(hello) ;; "Hello, World!"

If you make changes to the file and save it they will not be reflected in your REPL until you re-load the file using Ctrl + Shift + L.

Documentation

From a source file or from the input pane in the REPL, Ctrl + click (or Ctrl + B) on a function name to see the source code.