Ask coding questions

← Back to all posts
1
Java and C++ REPLs
Zwxwvut (9)

Ok, I'm not sure if this is just me or not... But pretty much everything when it comes to Java and C++ REPLs is broken. The little yellow greater than sign that appears below the version of the language doesn't appear. Everything for input is a rectangle, when the area doesn't have focus it is just an outline, when it does it's completely white. Also, when the program ends, the greater than sign still doesn't appear, the cursor doesn't change. Also, (this is the weirdest), on input when I hit arrow keys, something strange happens. For up arrow key: ^[[A, down arrow key: ^[[B, for right arrow key: ^[[C, for left arrow key: ^[[D. If someone could fix this it would be great, thanks!

Commentshotnewtop
1
slump3301 (1)

c++ and Java are pretty old and come from a time where no languages could execute code in the shell. python is able to do that because it is a scripting language and it is build into the language itself. If you want a shell to type in commands to execute, compile, etc. you can right click anywhere over the code, click on command palette, then search and click on "Open Shell" and then under the main console a terminal shell will open. In simpler terms c++ and java are extensions of other languages that are older than themselves. c++ is an extension of c and java is an extension of c++. Java and c++ dont support any kind of interface by default and it needs to be implemented/imported with extra code ex: "#include<iostream>" and "import java.util.Scanner;". to have an interactive mode like in python for java and c++ you would need to download an IDE that has such a feature or get a library that implements it such as JShell for java. Also with java(idk about c++) the java run environment only runs upon compiling and executing, so inputting code directly into the console would be very inefficient as the repl would have to start the runtime enviroment, compile, cache memmory, and execute individual lines of code instead of entire files. as for the "^[[A" input for the arrow keys, that occurs because the console takes direct byte input. in java and c++ it is just a regular input/output stream so it only uses bytes. Every key on your keyboard has an numerical value ex: when you press tab your keyboard outputs a char with the ascii value of 9. if you want to visually represent 9 as a char it would be '\t' but you don't see this elsewhere because your devices OS processes that char and recognizes that it has function. Lastly as a quick tip, if you want to paste something into the console or terminal shell you have to right click instead of ctrl+c or ctrl+v because those are also their own chars.

1
theangryepicbanana (657)

Repl.it has recently released their xterm console, which works differently from the old console. Maybe there will be an option at some point to change this.