1 # An experimental Nit interactive interpreter
3 This tool is outside src/ because:
5 1. Is is greatly experimental
6 2. It can depend on readline (GPL3) whereas the rest of nitc is Apache2.
7 Both are compatible but the final binary result is GLP3.
11 * use GNU readline to read lines
12 * use importation/refinement to handle incremental execution (so basically everything works out of the box)
13 * maintain an interpreter and live objects (the model grows but the interpreter and runtime data are reused)
14 * runtime errors/aborts return to the interactive loop
18 * top-level variables are local
20 * No model/object inspection
24 `-->` is the prompt, `...` the continuation prompt. What follows is the user input.
25 The rest is the output.
27 ### Basic instructions
35 ### Complex and control statements
48 You can use `do` blocks to delay the execution and control the scope of variables.
53 ...for i in [0..50[ do
61 ### Classes and methods
75 In case of static errors, the history (up arrow) can be reused and updated.
81 ^: Syntax Error: unexpected keyword 'end'.
82 -->class A **up arrow and update, thanks readline**
84 1,7: Redef Error: `A` is an imported class. Add the `redef` keyword to refine it.
87 -->redef class A **up arrow and update again, thanks readline**
88 redef fun foo do print "Bye"
96 Already instantiated objects gain the new methods, attributes and specializations.
97 However, the new attributes are left uninitialized (default values or init are not recomputed on existing objects)
99 Top-level methods automatically refine Sys.
103 1,1--3: Error: method or variable `foo` unknown in `Sys`.
113 You can store global variables as attributes of Sys
117 ...var my_int: Int is writable
124 ### Dynamic importation
127 -->print([0..10[.to_a.to_json)
128 1,20--26: Error: method `to_json` does not exists in `Array[Int]`.
129 print([0..10[.to_a.to_json)
132 -->print([0..10[.to_a.to_json)
133 [0,1,2,3,4,5,6,7,8,9]