REPL Output Formatting Broken
Opened this issue · 2 comments
I have been working my way through Practical Lisp's examples and have a file with the basic "testing" functions and macros they describe in the book. When loading the file and running the test-arithmetic
function, the first line is formatted oddly in the REPL, but subsequent lines are correct. Invoking a single call to the function that produces the output is also formatted oddly, so it looks like it might be an issue with the first item sent to the REPL output?
hello.lisp
(defvar *test-name* nil)
(defun report-result (result form)
(format t "~:[FAIL~;pass~] ... ~a: ~a~%" result *test-name* form)
result)
(defmacro with-gensyms ((&rest names) &body body)
`(let ,(loop for n in names collect `(,n (gensym)))
,@body))
(defmacro check (&body forms)
`(combine-results
,@(loop for f in forms collect `(report-result ,f ',f))))
(defmacro combine-results (&body forms)
(with-gensyms (result)
`(let ((,result t))
,@(loop for f in forms collect `(unless ,f (setf ,result nil)))
,result)))
(defmacro deftest (name parameters &body body)
`(defun ,name ,parameters
(let ((*test-name* (append *test-name* (list ',name))))
,@body)))
(deftest test-+ ()
(check
(= (+ 1 2) 3)
(= (+ 1 2 3) 6)
(= (+ -1 -3) -5)))
(deftest test-* ()
(check
(= (* 2 2) 4)
(= (* 3 5) 15)))
(deftest test-arithmetic ()
(combine-results
(test-+)
(test-*)))
Output:
ciel-user> (load "hello.lisp")
=> T
ciel-user> (test-arithmetic)
pass ... (TEST-ARITHMETIC
TEST-+): (=
(+
1
2)
3)
pass ... (TEST-ARITHMETIC TEST-+): (= (+ 1 2 3) 6)
FAIL ... (TEST-ARITHMETIC TEST-+): (= (+ -1 -3) -5)
pass ... (TEST-ARITHMETIC TEST-*): (= (* 2 2) 4)
pass ... (TEST-ARITHMETIC TEST-*): (= (* 3 5) 15)
=> NIL
ciel-user> (check (= 3 4))
FAIL ... NIL: (=
3
4)
=> NIL
ciel-user> (check (= 4 4))
pass ... NIL: (=
4
4)
=> T
thanks for the report. I am not surprised, the terminal REPL is not a top-notch REPL, yet. But it isn't the only way to use CIEL.
I can only encourage to use a good CL editor: https://lispcookbook.github.io/cl-cookbook/editor-support.html
We'll fix and tune the readline interface with time.
Other candidates worth checking out are:
- cl-repl: a more advanced, ipython-like shell: https://github.com/lisp-maintainers/cl-repl
- ideally we would build on top of it
- Lem, of course (it has a ncurses interface)
NB: the build-without-deploy
branch has been merged on master. (context: it simply removes the Deploy tool from the build process, as we don't need it anymore to help with foreign dependencies)
when you run your file as a script, the format is correct:
$ ciel testarithmetic.lisp
pass ... (TEST-ARITHMETIC TEST-+): (= (+ 1 2) 3)
pass ... (TEST-ARITHMETIC TEST-+): (= (+ 1 2 3) 6)
FAIL ... (TEST-ARITHMETIC TEST-+): (= (+ -1 -3) -5)
pass ... (TEST-ARITHMETIC TEST-*): (= (* 2 2) 4)
pass ... (TEST-ARITHMETIC TEST-*): (= (* 3 5) 15)
(instant result: 0.02s
)
but of course, we want to avoid a boring write-run loop, hence the use of (load "test.lisp")
in the REPL, etc.
For the best editing experience, anyways, I can only recommend to install… etc etc.