FLX is a mixture of two languages: Kotlin and Lisp. The syntax is mostly Kotlin, but under the hood everything is based on Lisp. And like in most Lisp languages, the basic building blocks in FLX language are called forms. In FLX, forms are either functions or data objects. Below is the classic Hello World example written in FLX. It simply prints a line “Hello World!” to FLX Console.
Visual Code Forms
In FLX language, the forms are actually used as visual forms which can be manipulated via touch user interface. Here are examples of most important visual form types:
Boolean values: true and false. (Same as in Kotlin).
Numbers: Int, Float, Double, Long and Byte. (Same as in Kotlin). Numbers and other basic data types are described in more detail in Section Basic Data Types.
Null is actually an object with member functions. It corresponds to null in Kotlin and NIL in Lisp. It also acts as a logical false value along Boolean false.
String, Char, and Keyword
String, Char, and Keyword. String and Char are from Kotlin. Keyword is from Lisp and always represent itself and evaluates to itself.
Symbol with Immutable Value
Immutable value symbol. Corresponds to val property in Kotlin.
Symbol with Mutable Value
Mutable value symbol corresponds to var property in Kotlin.
In addition to var and val symbols, FLX has a plain symbol which is used to define method or callback parameters, or used just as a symbol that can have arbitrary value – like symbols in Lisp.
Array, List, and Set
The collection objects Array, List, and Set in FLX correspond to Kotlin types Array<Any>, List<Any>, and Set<Any>.
Map in FLX corresponds Map<Any,Any> in Kotlin. A Map can be converted to a JSON object and vice versa. Collection objects are described in more detail in Section Basic Data Types.
FLX has a dedicated object type for JSON with a number of related function as described in JSON API.
A Code Block is a special form that can contains, as name suggest, code but on a nested level. A code block is not a scoping block which means that all the definitions given inside a code block are visible also outside of the block. This is because code block are used, for instance, for:
- Organising code
- Defining reusable code libraries consisting of constant, variable, and function definitions.
Regular expressions have a dedicated object type in FLX. The patterns for regular expressions are same as in Java/Kotlin. See, e.g, Kotlin regular expressions.
Markup Text Object
FLX has a special widget called MarkupText which can be used to display text formatted using a markup notation. The text to be displayed with this widget is defined as a Markup text object. The markup notation is based on CommonMark Spec.
BeanShell Script Object
Java Class Object
Since FLX is an Android app it is implemented using Kotlin – and Java. That is why FLX provides also the Reflection API which can be used to access and use underlying Kotlin/Java classes, objects, properties, functions, and methods.
All FLX widgets have colour related properties, that is why FLX provides a dedicated RGBA Color object for defining colors.
Date object is one of the special objects provided by FLX.
Audio Resource Object
Image Resource Object
Images are displayed with the Image widget in FLX. To define and manage image resources an Image resource object is used.
Example of FLX Visual Code
Below is an example of FLX code that makes a HTTP request to obtain a joke and asynchronously, via a callback, prints the joke to the FLX console. The example code shows usage of forms briefly introduced above. In addition to those, the example shows a number of function forms which are described in Section Functions.
- Definition of an immutable value (val) named with symbol “api“. The value is a String that contains a valid URL.
- Definition of a Callback object which is created by invoking function callback with two parameters: A code block and a symbol named “response”. A code block contains nested code (see bullet #4). Symbol “response” is used to pass value from invoker of Callback object to code block (see bullet #5).
- Function GET that implements HTTP method GET. The url is contained by value “api”. A GET request is asynchronous and needs a Callback object which in this example is assigned to symbol “callback”.
- Nested code for the Callback object.
- A callback parameter “response” that was defined for the callback (see bullet #2). FLX’s visual code editor provides this form automatically inside a code block.
- Instance function HttpResponse.valueAsJson is used to get the JSON payload from a received HttpResponse instance. The JSON object is assigned to be the value of symbol “json”.
- The actual joke String is obtained from the JSON using a property key “value”. The String is assigned to symbol “joke”.
- Finally println function is used to display the joke String to FLX console.