
Fansh
Overview
The fansh
is a very simple interactive shell for exploring Fan. 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\win>fansh Fan Shell v1.0.19 ('?' for help) fan> 3 + 4 7 fan> "3" + 4 34 fan> [3, 2, 9, 1].sort.join("|") 1|2|3|9 fan> 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\win>fansh Fan Shell v1.0.19 ('?' for help) fan> x := 5 5 fan> y := 7 7 fan> z := [x, y] [5, 7] fan> 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:
fan> c := sql::Connection.open("jdbc:mysql://localhost:3306/sql_test", "root", "") fan.sql.Connection@dc67e fan> c.query("select * from Foo")
Limitations
Currently the Fan 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 Fan code as a script.