alda icon indicating copy to clipboard operation
alda copied to clipboard

In REPL, codes cannot have multiple lines

Open UlyssesZh opened this issue 4 years ago • 4 comments

It is really limiting the existence of complicated lisp codes in alda repl codes.

UlyssesZh avatar Apr 13 '20 07:04 UlyssesZh

Some sort of multi-line editing would make the REPL experience better, for sure.

It seems like it might be a bit tricky to implement. I would probably want the parser to return some kind of error code to indicate when there is a parse error where we reached EOF unexpectedly, and then respond to that error code in the REPL by going down to the next line and continuing to accept input. Then this process could continue each time the user presses Enter -- either the code would be submitted successfully or we would go down to the next line.

It looks like multi-line reading is supported in JLine 3, so we could leverage that, although it would require an upgrade from JLine 2 which we're currently using.

I'm in the middle of a ground-up rewrite of the client in Go, so I'll explore options there when I get to reimplementing the REPL.

In the meantime, adding multi-line support to the existing Java client would be a welcome contribution, if anyone wants to tackle it!

daveyarwood avatar Apr 13 '20 13:04 daveyarwood

Maybe it can be taken that: if the last character of the line is a backslash, let the repl parser continue to the next line.

UlyssesZh avatar Apr 13 '20 13:04 UlyssesZh

That's another possibility. And another option is to provide a separate mapping like Ctrl-Enter that goes down to the next line instead of submitting.

daveyarwood avatar Apr 13 '20 14:04 daveyarwood

I am new to alda-lang and I was about to report the same feature request.

I feel that having this support will allow much quicker iterations for coder/musicians. (Otherwise we will be forced to first save code snippet to experiment to a file, then run ./alda play -f to run; which works, but defeats the purpose of having a CLI.)

Some approaches to implementing (potentially relatively easily) this that came to my mind:

  • iPython shell - with %cpaste - https://stackoverflow.com/a/10886947
  • Haskell REPL - enclosing with :{ and :} - https://github.com/elm-lang/elm-repl/issues/141#issuecomment-381409752

xcoderreal avatar Sep 12 '21 21:09 xcoderreal