3. Fansh


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:

Fantom Shell v1.0.19 ('?' for help)
fansh> 3 + 4
fansh> "3" + 4
fansh> [3, 2, 9, 1].sort.join("|")
fansh> quit


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:

Fantom Shell v1.0.19 ('?' for help)
fansh> x := 5
fansh> y := 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

Or you can import a pod via the using a statement:

fansh> using inet
Add using: using inet
fansh> IpAddr("www.google.com").numeric
fansh> scope

Current Usings:
  using inet

Current Scope:


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.