Hi there, I am a big fan of scala and exciting about new scala 3. I already installed coursier and type this command $cs setup --jvm adopt:11 following this setup.
Then, I recognize that it is scala 2.13, so I use this command $cs install scala3-compiler and $cs install scala3-repl following dotty docs.
The issue is here, when I tried to use repl using $scala, the welcome prompt showed that is is scala version 2.13.6 which can use :paste just fine. But for repl scala 3 version using scala3-repl, it seems that I canât use :paste as shown in the figure below. I wonder why?
Actually, I would like the default $scala command to access scala3 version repl like in this online book. How can I do this?
Multiline paste is not same as :paste . For example, how do we get companion object. People who have removed :paste, really have not used scala REPL. Poor replacement is using block
Pasting code that includes a companion object works fine as far as I can tell. If it isnât working for you, please be specific about what youâre doing and how itâs failing.
Here is a session log showing it working:
% scala3
Welcome to Scala 3.1.0 (1.8.0_292, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
scala> class C
| object C
|
// defined class C
// defined object C
scala>
Do we have two Scala 3 REPL? Because in my case, your snippet does not work (Logically should not work as well because why would REPL wait for next line when âclass Aâ has ended as per REPL. Also @luigip 's example is valid one as that also does not work)
Welcome to Scala 3.1.0 (1.8.0_65, Java Java HotSpot(TM) 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
scala> class A
// defined class A
scala> class A
// defined class A
scala> object A
// defined object A
scala> class A{
| };object A
// defined class A
// defined object A
scala> class A{
| }
// defined class A
scala>
Iâm at a loss to account for why this works for me and doesnât work for you. But your experience apparently isnât common, or weâd have had a ton of complaints about it.
Iâm on macOS, for whatever itâs worth. Sometimes there are JLine peculiarities that are Windows-specific. Are you on Windows, perhaps?
Yes, Sir, you are right. I am at Windows and at âsbt consoleâ . Looks like then, we have a issue here in Windows. BTW, I am curious, how does scala REPL understand when to end user input in mac? If newline is not the end for logical block (eg in this example âclass Aâ), then what is the logical end for mac scala repl? Is it one empty line?
Let me help you out here. I think @SethTisue is talking about actually pasting code into the REPL and @ndas1971 about typing code into the REPL but wanting multiple lines to be interpreted together.
You can enter multiple lines by using âsoft returnâ. My best guess is that that would be Shift+Enter on Windows. Thereâs also a slight chance you have to configure something in your terminal application for that to work (like I had to do).
Thanks for the Help, it is Esc+Enter in Windows. Could find out with all key combinations as google search only talks about Office productsâ soft return.
Again after using REPL on windows extensively , I would like to say that without :paste, "copy and paste"ing code is really troublesome . Work around âblockâ compiles immediately and soft return is really not workable in cut and paste(useful only in manually typing code). Does anybody have any better workaround for copy+pasting code in REPL?