yitzchak / common-lisp-jupyter

A Common Lisp kernel for Jupyter along with a library for building Jupyter kernels.
https://yitzchak.github.io/common-lisp-jupyter
MIT License
218 stars 29 forks source link

read-line not prompts in loop #94

Closed Schroedingersdoraemon closed 2 years ago

Schroedingersdoraemon commented 2 years ago

Dear yitzchak, thanks for this common-lisp-jupyter first.

the simple code below runs differently in jupyter notebook/lab/console and sbcl directly.

(loop (read-line *query-io*)
    (if (not (y-or-n-p "Continue?")) (return) )
)

When in jupyter notebook/lab/console, the (read-line) sometimes disappears and becomes the infinate loop of (y-or-n-p), but when runs in sbcl from terminal the (read-line) appears as expected.

It will be much appreciated if the reason could be found

yitzchak commented 2 years ago

I pushed a potential fix. Also, if you use loop clauses versus the implicit do variation of loop you can avoid the return and the awkward if.

(loop for line = (read-line *query-io*)
      while (y-or-n-p "Continue?"))
Schroedingersdoraemon commented 2 years ago

Dear yitzchak,

thanks for your fix, now the (read-line) becomes available in the loop every time.

But, the result of (read-line) is REVERSED

If I input 123456 in (read-line), the returned value is 654321

image

yitzchak commented 2 years ago

Try now.

Schroedingersdoraemon commented 2 years ago

Dear yitzchak,

sorry for the delayed reply,

the (read-line) works exactly as expected every time,

I am a Lisp beginner and very fond of the Jupyter-style environment, thanks for your quick answers and fixes :)