Values and Data types

TIScript is a dynamically typed language. That means that the variables can contain values of any supported type. Types are:

The value of the Integer class; a 32-bit signed integer between Integer.MIN and Integer.MAX. If you have definition var i = 3; then following statements are both equal to true:  
typeof i == #integer;
i instanceof Integer;
The value of the Float class; a 63-bit floating point number between Float.MIN and Float.MAX. The following statements both evaluate to true:  
typeof 3.14 == #float;
3.14 instanceof Float;
The value of the String class; an immutable sequence of UNICODE characters. The following statements both evaluate to true:  
typeof "abc" == #string;
"abc" instanceof String;
The value of the Symbol class. A symbol (otherwise known as atom) is a unique integer value, assosiated with a name. Internally, symbols are represented by 32-bit integers. Symbols are defined as a name token that’s also allowed to have - characters, preceded by the # character. Examples of valid symbols are: #integer, #foo, #Bar, #sub-script. Examples of invalid symbols are: #123, #1abc. Symbols are resolved into unique integer value at compile time. So, the comparison of two symbols is as computationally effective as the comparison of two integers. In TIScript, symbols are used as the names of object attributes. Hence, the expression obj.foo = 1; is a close equivalent of obj[#foo] = 1;. The following two statements both evaluate to true:  
typeof #abc == #symbol;
#abc instanceof Symbol;
An array is an indexed sequence of elements – values. Elements of the array can be accessed by the [index] operator, where index is an integer value – the sequence number of the element in the array. Indexes in arrays start from 0 (zero). If you have a variable defined as var a = [1,2,3];, the following statements all evaluate to true:
typeof a == #array;
a instanceof Array;
a[0] == 1; a.length == 3;
The value of the Object class; a collection of "named values" – pairs of names (a.k.a. key) and values assigned to those names. As in JavaScript, objects here are universal entities. They can be used as a map (hash map) of name/value pairs, or as real objects – instances of user-defined classes. If the obj variable has an object assigned to it, the following statements both evaluate to true:
typeof obj == #object;
obj instanceof Object;
The value of the Function class. Functions are first-class entities of the language. Once defined, a function can be assigned to any variable, and passed as a parameter to function calls. If you have the following statement:
var foo = function(p) { return  p + 1; }, the following two statements evaluate to true:
typeof foo == #function;

foo instanceof Function;
The value of the Class class; allows to define classes of objects with a specific set of methods and attributes. If you have the declaration:
class MyClass { function myMethod() { ... } }  
you can create instances of the class using the new operator ( var obj = new MyClass() ).
The following statement evaluate to true for all classes:
typeof MyClass == #class;
Namespace is an object (of class Class) that groups multiple variables, constants, and methods into a single named entity. Thus, if you have the declaration:
namespace MyNamespace { const myConst = 12; function myMethod() { ... } }
you can refer to the members of the namespace using the dot notation as: MyNamespace.myMethod() and MyNamespace.myConst
Length values represent lengths – numeric values with unit designators. Length units literals are numbers immediately followed by unit characters. For example, 12px is a value representing 12 pixels,  126mm is 126 millimeters length. See the description of  the Length class for more details. Internally, length values are represented as fixed point values with 0.001 precision. The following statements evaluate to true:
typeof 12.6cm == #length;
12.6cm instanceof Length;
12.6cm.units == #cm;
12.6cm == 126mm;

List of supported length literal/unit types:

  • em, ex – em and ex logical CSS length units;
  • px – physical device pixels;
  • dip – device indepenedent pixels, logical unit equal to 1/96 inch;
  • mm, cm – metric length units, centimeters and millimeters;
  • in, pt, pc – royal length units: inch, point and pica (as they defined by CSS);
  • fx – flex unit (Sciter specific) – defines portion of free space: 1fx is an equivalent of 1*  or 100%% in Sciter’s CSS;
  • pr – percent units, 100pr is an equivalent of 100% in CSS;
Angle values represent angles – numeric values with unit designators. All these expressions evaluate to true:
360deg instanceof Angle;
360deg == Math.PI * 2 * 1rad;
360deg == 400grad;
360deg == 1turn;
1turn / 2 == 180deg;

TIScript supports all angle units defined by CSS:

  • deg  – degree, there are 360 degrees in full circle;
  • rad – radians, 2*π radians in full circle;
  • grad – gradians, 400 gradians in full circle;
  • turn – turns, 1 turn is exactly 360 degree – one full circle;
Duration values represent time duration – numeric values with unit designators. All these expressions evaluate to true:
5s instanceof Duration;
5s == 5 * 1000ms;
1s == 1000ms;

TIScript supports both duration units defined by CSS:

  • s  – seconds;
  • ms – milliseconds;
The value of the Color class. Color values represent colors – structures that have the red, green, blue, and the optional alpha fields. Color values are constructed by the color(red,green,blue[,opacity]) function. The following statements all evaluate to true:
typeof color(0xFF,0,0) == #color;
color(0xFF,0,0) instanceof Color;
color(0xFF,0,0).red == 0xFF;
color(0xFF,0,0).blue == 0;
The value of the Date class. Date values represent date and time, and are constructed by using the new operator:
var date = new Date(2009,7,15).
THe following statements evaluate to true:
typeof date == #date;

date instanceof Date;
date.day == 15; date.year == 2009;
The value of the Bytes class. An instance of Bytes is an array (sequence) of byte values (integers in range 0 .. 255). The following statements all evaluate to true:
typeof (new Bytes(12)) == #Bytes;
(new Bytes(12)) instanceof Bytes;
(new Bytes(12)).length == 12;
Tuple (n-tuple to be precise) is a tagged sequence of values. Tuples have operator[] to access elements of the tuple. Once created tuple cannot change its length. Tuples have read-only length  property and read/write tag property. If you have something like this defined:
var tup = [tname: 1, "two" ];
then following statements will all evaluate to true:
typeof tup == #tuple;

tup instanceof Tuple;
tup.length == 2;
tup[0] == 1 && tup[1] == "two";

tup.tag == #tname;
The value of the Stream class. A stream represents a sequence (possibly unlimited) of elements called stream units. TIScript supports various types of streams that can be created via the Stream.open**** methods:
var stream = Stream.openSocket("");
The following statements all evaluate to true:
typeof stream == #Stream;
stream instanceof Stream;
Regular expression
The value of the RegExp class. A RegExp object is a compiled reqular expression. It is also used for storing information about the results of regular expression pattern matches. Regular expressions can be created by the constructor function of RegExp class, or by the RE-literal:
var re = /ain/i;                   // RE literal
r = "The rain in Spain".match(re); // attempts to match search string
assert r == "ain";