Can you program without REPL on Lisp?

我与影子孤独终老i 提交于 2019-11-29 15:39:54

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!