wren-cli icon indicating copy to clipboard operation
wren-cli copied to clipboard

Handle multiline input in the REPL

Open sturnclaw opened this issue 9 years ago • 5 comments

While messing about with Wren's CLI, I noticed a few issues.

Firstly and most pressingly, when mucking about in the CLI, any error (at least with undefined variables) is fatal, to the point of requiring a new wren CLI session. For example:

> System.print(SOME_UNDEFINED_VAR)
(Error message)
> System.print("Valid String!")
(Exact same error message)

Any valid code after that first System.print refuses to work. Period. Tested on both mainline master and my custom linenoise fork.

Secondly.

> class Test {
(ERROR!)
> class Test {}
(ERROR! Test is already defined!)
> System.print(Test)
null

You can probably see the issue. Classes and blocks really should allow definitions across multiple lines, and a REPL-mode class definition error should fail without creating the class.

Regular files are fine, just the CLI in REPL mode gets these errors. This unfortunately renders the CLI unusable as a prototyping tool.

sturnclaw avatar Mar 27 '16 02:03 sturnclaw

Firstly and most pressingly, when mucking about in the CLI, any error (at least with undefined variables) is fatal, to the point of requiring a new wren CLI session.

Oof, that's definitely not intended! Thanks for filing the bug.

Classes and blocks really should allow definitions across multiple lines, and a REPL-mode class definition error should fail without creating the class.

Yeah, I totally agree. The REPL needs some work, but it's surprisingly tricky to do well, and I haven't had the time to dig into it yet. I tend to just re-run a temp script instead of using the REPL when I'm hacking stuff, so it's not on my own critical path.

munificent avatar Apr 05 '16 23:04 munificent

FYI I am unable to reproduce the first part of this issue now building from HEAD. Example CLI session below:

\\/"-
 \_/   wren v0.1.0
> System.print(undefined_variable)
[repl line 1] Error at 'undefined_variable': Undefined variable.
> System.print("Bilbo Baggins")
Bilbo Baggins
Bilbo Baggins

cacciatc avatar Aug 03 '16 21:08 cacciatc

Yeah, that part is working for me too, I'll update the bug. @Web-eWorks is definitely right that the REPL should support multi-line input. I just haven't gotten there yet. :)

munificent avatar Aug 26 '16 13:08 munificent

What other REPLs do we know of that support multi-line input? I'd like to try one and see how it works.

joshgoebel avatar Sep 22 '21 22:09 joshgoebel

Tcl

$ tclsh
% foreach x {1 2 3 4} {
    puts ">>> $x"
}
>>> 1
>>> 2
>>> 3
>>> 4

Tcl has a builtin info complete $code command that I'm sure the REPL uses.

glennj avatar Sep 23 '21 13:09 glennj