technoblogy / ulisp-esp

A version of the Lisp programming language for ESP32-based boards.
MIT License
110 stars 37 forks source link

`(read-line)` processes backslash escapes when it shouldn't (it uses readstring()) #67

Closed dragoncoder047 closed 1 year ago

dragoncoder047 commented 1 year ago
> (read-line)
foo \
bar
"foo
bar"
> (read-line)
foo \bar
"foo bar"

Common Lisp does not do this:

CL-USER> (defvar s "foo \\
bar")
"foo \\
bar"
CL-USER> (defvar st (make-string-input-stream s))
#<INPUT STRING-INPUT-STREAM>
CL-USER> (princ (read-line st))
foo \
"foo \\"

I think the intention of (read-line) was to ignore backslashes and include them.

technoblogy commented 1 year ago

Good point - thanks.

dragoncoder047 commented 1 year ago

I think an easy solution would be to have a third parameter doEscape and pass true in (read) and false in (read-line).

technoblogy commented 1 year ago

Yes, I was thinking along the same lines. On the todo list.

dragoncoder047 commented 1 year ago

It just dawned on me that you could implement something like (make-string-input-stream) / (with-input-from-string) by simply using gstr(). Unfortunately until #64 is resolved it will only work for one stringstream, but that's already an inherent limitation with the current implementation.

technoblogy commented 1 year ago

Good point. I've already got with-output-to-string so I don't know why I didn't include with-input-from-string.