Read Eval Print Loop (REPL)
You interective with your Lisp system through a build-in piece of code called the toploop, which repeats three simple steps for as long as you run the Lisp system.
You interective with your Lisp system through a build-in piece of code called the toploop, which repeats three simple steps for as long as you run the Lisp system.
- Read an expresion.
- Evalue the expresion just read.
- Print the result of the evaluation.
Let's do it
(defun my-toploop ()
(loop
(terpri); print a new line
(princ 'ready>) ;print phase
;; displays the result of the evaluation
(print (eval (read)))))
And some functions to call
(defun hello ()
(format t "Hello!"))
(defun test (x)
(+ x 10))
Try it!
CL-USER> (my-toploop)
READY>
READY> (+ 5 5)
10
READY> (hello)
Hello!
NIL
READY>(test 5)
15
READY>
Getting out of you toploop
enter an erroneus expression like ( + 2 'a)