CHAPTER 24
Like most other languages, Julian provides an interactive console that bring REPL (Read-Evaluate-Print) experiences to users. Since Julian is still in its early days, you will find the console particularly useful in your development routine as it can help you quickly validate the correctness of the code.
~> julian -i
This will override -s or -f options.
Now the user can input code after the prompt:
>>> _
(1) The interpreter executes per line. When the user completes one line (by EOL char) it will trigger execution. To ease the use, a ';' is automatically complemented if absent. But there are exceptions to this rule.
(2) If the first line ends with { and it's determined to be a type declaration (class/interface/etc.), the interpreter enters into type definition mode. In this mode, it will keep receiving input until a matching } is hit, ignoring EOLs in between. An example of this:
>>> class A {
... void fun(){ }
... int fun2(){
... return 5;
... }
... } // This is the matching '}', signaling the end of type declaration.
>>> _
If a matching '}' is found in a line with other characters following, it incurs an error and the type def mode bails out.
(3) Similarly, if the first line ends with { and it's determined to be a function declaration, the interpreter enters into function definition mode. This mode is very similar to type definition mode.
>>> void fun(){
... return 5;
... } // This is the matching '}', signaling the end of function declaration.
>>> _
(4) The user may conclude a line with an independent '' to explicitly ask for continuation. But once in the explict continuation mode, further '' is not needed. The input must be finished by an explicit ';'.
>>> Console.println \
... ("some text" \ // This \ is not really needed.
... };
some text
>>> _
(5) The user may use arrow key (up/down) to browse command history and rerun a command.
(1) The input will be evaluated in a single and continuously existing context.
(2) If a type is defined, it's loaded into the context immediately. This is different from the behavior of Julian in script mode, where it always defers loading to the point when the type is actually needed.
(3) Any exception will be captured and printed out.
If the input contains one or more expressions, the result of last expression will be printed out, unless it is a void.
>>> 3
3
>>> 2 + 3
5
>>> fun() // fun() returns a string "something returned by fun()"
something returned by fun()
>>> fun2() // fun2() returns void
>>> _
(1) Meta commands are input in the format of ".comm args"
>>> .help
(2) List of meta-commands (commands greyed out are not available yet as of 0.1.34)