wren-cli
wren-cli copied to clipboard
Handle multiline input in the REPL
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.
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.
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
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. :)
What other REPLs do we know of that support multi-line input? I'd like to try one and see how it works.
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.