I was trying out jshell and couldn't find option to paste multiple line expressions. Is it even possible to paste multiple lines in jshell. Similar to what scala offers with paste mode
.
Before entering your multiline statement, type the :paste command into the REPL: When you do this, the REPL prompts you to paste in your command — your multiline expression — and then press [Ctrl] [D] at the end of your command. In this example I paste in my complete multiline if statement, and then press [Ctrl] [D]:
As for pasting multiple lines: well, you can paste multiple lines, but it only seems to evaluate the first one. What you can instead do is nest those multiple lines in a function, and then paste it.
Before entering your multiline statement, type the :paste command into the REPL: scala> :paste // Entering paste mode (ctrl-D to finish) When you do this, the REPL prompts you to paste in your command — your multiline expression — and then press [Ctrl][D] at the end of your command.
I found ActivePython lacking in features (dedent region, indent region, comment region, uncomment region) yet containing no new (useful) ones. As for pasting multiple lines: well, you can paste multiple lines, but it only seems to evaluate the first one. What you can instead do is nest those multiple lines in a function, and then paste it.
So if you have code like this:
int c = 2;
int j = 4;
int x = 5;
Copy and paste into jshell, only the first two statements are processed.
But if you have code like this:
int c = 2; int j = 4; int x = 5;
And paste into jshell:
jshell> int c = 2; int j = 4; int x = 5;
c ==> 2
j ==> 4
x ==> 5
Even more lines of code like this:
HashMap<Integer, Integer> map2 = new HashMap<>(); for (int i = 0; i < 15; ++i) { map2.put(i, i);map2.put(i, i); } System.out.println(map2);
will actually work.
Why? Me don't know.
The only way I know that copy/paste will work is via (type it in jshell) :
/edit
and you can paste as much as you want.
Just in case people still end up here, a small tweak to paste in an entire code block to jshell
is to wrap it around with braces {}
as:
{
int c = 2;
int j = 4;
int x = 5;
// access these only in this scope though
System.out.println("c : " + c + ", j : " + j + ", x = " + x);
}
Sample screen:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With