Can you program without REPL on Lisp?
Asked Answered
K

1

3

So I just got Land of Lisp and started to do the first program. I have a couple questions.

Is there a way to just write some code and run it through a compiler, or interpreter, and not use the REPL thing? I don't like it much. I can't seem to go back if I messed up. It just kinda says "Ha you screwed up, retype that whole function."

I would also like to know what the point of REPL is.

Knapsack answered 29/3, 2013 at 18:8 Comment(1)
Check the functions compile-file and load For documentation: see lispworks.com/documentation/HyperSpec/Front/Contents.htmBencher
L
19

Non-REPL work flow

  1. Edit your file
  2. Compile the file using compile-file; fix errors and warnings; repeat.
  3. Load the file using load; evaluate the form you want; repeat

Example

$ cat > f.lisp <<EOF
(defun f (x) (if (zerop x) 1 (* (f (1- x)) x)))
EOF
$ clisp -q -norc -c f.lisp
;; Compiling file /home/sds/f.lisp ...
;; Wrote file /home/sds/f.fas
0 errors, 0 warnings
$ clisp -q -norc -i f.fas -x '(f 10)'
;; Loading file f.fas ...
;; Loaded file f.fas
3628800
$ 

The Right Way

Use an IDE, e.g., Emacs with SLIME.

This way, you edit the code in an editor which supports auto-indent and shows you help for each standard symbol.

You compile and test the functions as soon as you write them, giving you a very short development cycle. Under the hood this is accomplished by the IDE interacting with the REPL (this answers your last question).

What is REPL?

Read-Eval-Print loop is a faster, more versatile version of the Edit-Compile-Run loop.

Instead of operating in terms of whole programs (which can be slow to compile and whose execution can be tedious to navigate to the specific location being tested), you operate in terms of a specific function you work on.

E.g., in gdb, you can execute a function with print my_func(123), but if you change my_func, you have to recompile the file and relink the whole executable, and then reload it into gdb, and then restart the process.

With Lisp-style REPL, all you need to do is re-eval the (defun my-func ...) and you can do (my-func 123) at the prompt.

Laskowski answered 29/3, 2013 at 18:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.