Scalars and Variables

Scalar value, or simply scalar, is a constant value such as: string, integer, real number and boolean.

Strings will be defined by the single quotation mark (quotation symbol) (), whereas that mark will be denoted by the back tick symbol (`), to enable inserting a quotation symbol in a string.

Integers are integral numbers including big numbers of any size, and including all negative numbers.

Real numbers are all numbers that have a decimal point. Note that the result of most system mathematical system functions are real numbers. Also, the suffixes “E+” (the symbol “+” can be omitted) and “E-” are also used to denote very big or small numbers with positive or negative powers of ten.

Booleans are bi-value objects, where the TRUE value is “\t” (symbol: t), and the FALSE value is “\f” (symbol: f).

Variables are programmatic objects that have a key, by which the system identifies them, and hold a value that can be scalar or other programmatic structure like list, record or module. Usually, variables that their value is scalar will be called scalar variables or simply variables, whereas list variables can be called lists etcetera.

If a scalar variable is declared without a value, its value is considered NULL, and that can be checked by system function “null” as demonstrated in the reference (program “null.till”).

Till system accesses variables by their key (the variable “name”), that can be any combination of characters provided that it starts with “_” or a letter and that it is not one of predefined system objects: system function, system variable or system module. All these reserved words can be found in directory “data” of the reference.

Throughout the reference there are lots of programs that demonstrate how to work with variables, including how to declare, assign, pass to a function, and use in programmatic structures: looping and conditional statements.

Here are some examples of variables use:

  1. declare scalar variable “stra” and assign the string value “string A”
  2. declare variables “inta” and “intb” as integer variables and assign the value 0
  3. declare variable “intc” and assign the result of adding 100 to the value of variable “inta”
  4. if “intb” is less than “intc”, then assign the value of “intc” to “intb”

Note that in the second statement, a key feature of Till programming is demonstrated which is the ability to declare some variables (optionally with a value) in the same declaration line.

Also pay attention that declaration lines can be similar to assignment lines, and it is important to locate variables declaration lines prior to analyzing statements of code.

In Till, variable types are dynamic and can be changed according to the functionality they are involved in. Here are some examples of it:

  1. declare variable “numstr” as string with value “100”
  2. add (append) string “1” to string “100”, resulting in “numstr” value equals “1001”
  3. assign “numstr” the result of applying system function “number.of” on it. “numstr” type will change to integer with value 1001
  4. apply system function “add and assign” (“++”) on “numstr” and 0.1 . “numstr” type will change to real number with value 1001.1
  5. assign “numstr” the result of applying system function “math.floor” on it. “numstr” type will change to integer with value 1001

The ability to declare and use variables without defining their type is called “automatic type inference”, and Till system is doing it automatically without user interference. System functions, usually, disregard the type and work according to their intention. For example, finding a section of string will evaluate the variable value as string and will work on it, whereas mathematic functions can expect any sort of numeric value to work with.

In cases where there is an incompatibility between expected and provided values, the system will alert the user about it. Therefore, it is good practice to pay attention to variable names, values, and use in code, that conform to regular programming conventions.