ciel-lang / CIEL

CIEL Is an Extended Lisp. Scripting with batteries included.
http://ciel-lang.org
346 stars 16 forks source link

REPL Output Formatting Broken #63

Open tpmoney opened 2 months ago

tpmoney commented 2 months ago

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
vindarel commented 2 months ago

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:

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)

vindarel commented 2 months ago

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.