Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REPL Output Formatting Broken #63

Open
tpmoney opened this issue Aug 31, 2024 · 2 comments
Open

REPL Output Formatting Broken #63

tpmoney opened this issue Aug 31, 2024 · 2 comments
Labels
bug:terminal-repl This happens only in the readline REPL, not in Slime help wanted Extra attention is needed

Comments

@tpmoney
Copy link

tpmoney commented Aug 31, 2024

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 vindarel added help wanted Extra attention is needed bug:terminal-repl This happens only in the readline REPL, not in Slime labels Aug 31, 2024
@vindarel
Copy link
Contributor

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
Copy link
Contributor

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.

@vindarel vindarel changed the title REPL Output Formatting Broken on build-without-deploy macOS build REPL Output Formatting Broken Aug 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug:terminal-repl This happens only in the readline REPL, not in Slime help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants