Link Search Menu Expand Document

Basic Types

Table of Contents

  1. Overview
  2. Atomic Types
  3. Collections
    1. Array
    2. Map
  4. Other Basic Types
    1. Datetime
    2. Random

Overview

FLY provides a set of types named basic types. Basic types are inherted by Java, and comprises boolean, integer, real (double point precision float) and string. Moreover, FLY supports one/bi/three-dimensionale array definition for basic types.

Atomic Types

An atomic type is a basic type on which other basic types relies. The following table contains all FLY’s atomic types and its literals.

Type Literal Examples
Integer Can be any digit, or group of digits followed by a white character. Can be negative. 1, -12, 392, -034
Boolean Can be true or false. true, false
Real Can be any decimal digit on wich the integer and decimal separator is the dot character. Can be negative. 0.134, 42.594, -1.0
String Can be any kind of character wrapped in a double quotes characters. Can be also the empty string. Moreover, all Java escapes characters are supported. "”, “Hello World!”, “c\n\n”, “S1t24”

Each of those basic types is inherited by Java atomic types (Real matches to Double).

Collections

A collection is just a group of atomic types, that are enclosed in a single variable or literal. Also the collection type in FLY are inherited by Java.

Array

Definition

Array basic type. We have introduced the array type. A Fly array is a collection of homogeneous basic types laid on a tabular form having one, two, or three dimensions. The declaration of an array is described in the following:

var arr = Integer|Real|Boolean|String [N][M][K]

where N, M and K are the array dimensions. If one of those dimension is 0, is just need to be omitted in the definition.

Arrays has also a literal definition:

var arr_1d = { 1, 2, 3 }
var arr_2d = { { 1, 2, 3 }, { 10, 20, 30 } }
var arr_3d = { { {1, 2, 3}, { 10, 20, 30 } }, { { 4, 5, 6 }, { 40, 50, 60 } } }

Access

FLY provides the brackets notation to access to an array element.

println arr_1d[0]
println arr_2d[1][0]

Also, arrays indexes can be a left-value of an expression.

arr_1d[0] = 101
arr_2d[0][1] = 241

Map

Fly maps are declared using braces ({…}) and can contains values ​​of heterogeneous types The mapping between object IDs and values are made using the assignment (=) symbol. For instance:

var ID = {?ID1=VALUE, ?ID2=VALUE, ...}

For example:

var map = {n=42, s="Universe Answare"}

To access to objects, the brackets notation is needed:

println map[n]
println map[s]
map[n] = "24"
map[s] = "Ciao"
map[new_id] = 24.5

We can add new elements to our map even after the declaration. Moreover the mapping is between a key and an object, so each object doesn’t need to be of the same type of the initialization one.

Object ID can be also omitted. In this case can access to that object trhough a positional index key:

var map = {"Hello!", "World!"}
println map[0], map[1]

Also we can use either positional index keys, or ID index keys:

var map = {"Hello", n=42, "World!", s="Universe Answare"}

Other Basic Types

FLY provides two more basic types, which are Datetime and Random. Those types are also inherited by Java, even if they are not basic types, FLY manages them as basic types.

Datetime

TODO

Random

The random object definitions reminds to Domain Object declaration. In formal way:

var rand = [type="random"]

Random objects can generates random values as the following:

rand.nextBoolean() // generates Booleans
rand.nextDouble() // generates Real numbers
rand.nextInt(MAX RAND) // generates Integer numbers