Evaluating individual expressions is a very effective way to test the actions of your code as you write it.
Evaluate code in the code buffer
Note Evaluate the namespace and function definition in
Then write an expression to call foo with a string argument, eg. (foo "Spacemacs ")
Note Now change the definition of the function
fooby replacing the
printlnfunction with the
strfunction. Both functions take the same arguments.
Evaluate code and send to repl
In the Clojure code buffer you can send individual expressions to the REPL to be evaluated
If the REPL is not in the namespace as the Clojure code buffer, you must send any definitions to the REPL before trying to use them. For example if you want to call a function, send that functions definition to the REPL first, then send the expression that calls that function.
Call code from the REPL
Switch to the REPL window,
M-RET s s. By default you will be in the
user namespace which does not include your code, so calling functions will return an error.
Use the function
in-ns to change to the
spacemacs-workshop.core namespace so you can call the functions defined in there.
You can also change the namespace in the repl from the Clojure code buffer using the function
M-RET s n.
Replace code with result
A powerful way to understand your code or explain to others what an expression does is to replace the code with result of its evaluation.
M-RET e w - replace previous expression with its return value
You can see the Clojure code that is created when evaluating a macro using
macro-expand. Expanding a macro can help you understand what that macro actually does
M-RET e m- replace previous expression with its return value
In this example we expand a simple
(defn foo "I don't do a whole lot." [x] (println x "Hello, World!"))