This is an example using RxKotlin to implement a simple REPL.
The supported commands are:
history(orhist)- display previously executed commands
- commands ending with "ck" are excluded (to emulate a profanity filter)
- consecutive duplicates are displayed only once
exit- ends application
- any arithmetic expression using integers and operators
+,-,*,/- display the result of the operation as though it were evaluated in Javascript;
- anything else
- just echo the command
There are two executable Kotlin files:
Repl.ktstarts the interactive REPL shell;FileRunner.ktreads a list of commands from filecommands.txtand executes them in sequence.