Fansh
Overview
The fansh is a very simple interactive shell for exploring Fantom. The shell allows you enter a one line statement or expression. If the result of the expression is non-void, then it will print the result via the Obj.toStr method. Enter "quit" to exit:
C:\dev\fan\bin>fansh
Fantom Shell v1.0.74 ('?' for help)
fansh> 3 + 4
7
fansh> "3" + 4
34
fansh> [3, 2, 9, 1].sort.join("|")
1|2|3|9
fansh> quit
Scope
If you enter a statement which declares a local variable or assigns a local variable, the shell will make that variable available to subsequent evaluations. You can enter the "scope" command to list the current local variables. An example:
C:\dev\fan\bin>fansh
Fantom Shell v1.0.74 ('?' for help)
fansh> x := 5
5
fansh> y := 7
7
fansh> z := [x, y]
[5, 7]
fansh> scope
Current Scope:
sys::Int?[] z = [5, 7]
sys::Int y = 7
sys::Int x = 5
Using Pods
You can use a fully qualified type name to import a pod:
fansh> inet::IpAddr("www.google.com").numeric
64.233.161.147
Or you can import a pod via the using a statement:
fansh> using inet
Add using: using inet
fansh> IpAddr("www.google.com").numeric
64.233.161.104
fansh> scope
Current Usings:
using inet
Current Scope:
Limitations
Currently the Fantom shell is quite limited compared to the shells of many other languages. You cannot enter a multi-line statement or expression. Also you cannot enter full type definitions. If you wish to explore the language using more than simple line statements, run your Fantom code as a script.