Skip to content

Commit ce88eef

Browse files
author
pnathan
committed
Add information on how to use the REPL
1 parent 488f5ab commit ce88eef

File tree

1 file changed

+51
-2
lines changed

1 file changed

+51
-2
lines changed

env~repl.md

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,54 @@ In this article we'll assume that you've configured your Lisp
1111
environment correctly and now are trying to write Lisp code
1212
(Congratulations)!
1313

14-
Let's say that you have your `emacs` and `SLIME` set up. Then, let's
15-
load our SLIME. `M-x slime`. This will create a REPL buffer for you.
14+
Let's say that you have your `emacs` and `SLIME` set up. Then, open a
15+
file and load our SLIME - run `M-x slime` when the file is opened.
16+
This will create a REPL buffer for you associated to the file.
17+
18+
Here's a function to put in the file (or write your own):
19+
20+
```Commonlisp
21+
(defun heads (&rest lists)
22+
"Gets the first elements of the lists"
23+
(mapcar #'car lists))
24+
```
25+
26+
Then place the cursor in the function and keyboard in the combination
27+
`C-cC-c`.
28+
29+
In my REPL window the annotation `; compiling (DEFUN HEADS ...)`
30+
appears. We then can run `heads` and see its output, just as if we had
31+
written heads on the prompt.
32+
33+
Not only that, the SLIME REPL offers lookup of symbol completion based
34+
upon what exists in the Lisp image: typing `hea` and then `TAB` in the
35+
REPL will attempt to complete heads (or present you with a list of
36+
possible completions).
37+
38+
I frequently use `M-x slime-eval-buffer` to reload everything in my
39+
file (just checking to ensure that it works correctly).
40+
41+
Let's invert this and use our actual file as a sort of REPL. Put an
42+
invocation of `heads` in your source file and run `C-xC-e` - this
43+
actually evaluates the form and outputs the result to the
44+
minibuffer. If you instead run `C-cC-j`, SLIME copies the form into
45+
the REPL and executes it. And, if you run `M-x
46+
slime-eval-print-last-expression`, then the expression will be
47+
evaluated and printed out into your executing buffer. This is very
48+
handy for scratch calculations and experimentation[1].
49+
50+
If you're working with large amounts of data, then the dynamic
51+
variables at global scope `*print-length*` and `*print-depth*` are
52+
very handy. When set to `nil`, then the length and recursive depth of
53+
data objects are printed to infinite length and depth; when given an
54+
integer, the Common Lisp printer obeys that integer as a limit on the
55+
length and depth of the printing.
56+
57+
58+
[1] P.s., an elisp snippet to make that command easier is:
59+
60+
```elisp
61+
(define-key slime-mode-map
62+
"\C-x\C-j"
63+
'slime-eval-print-last-expression)
64+
```

0 commit comments

Comments
 (0)