Till has built-in system objects that are part of Till Framework and can be used in Till coding. All objects have keys that are reserved for them and it is forbidden to use the keys for regular variables and functions keys.
In the reference there are directories “system variables” and “system functions”, that have a program for each system object with the object key as the file name.
System Variables
System variable is a predefined variable that gets its value by the system once upon program run. For example, system variables “appname” and “io.currentdir” are string variables that hold application (program) name and program’s current directory respectively, and system variable “screensize” is a record variable that holds screen width and height.
Using the system variables is done similar to user-defined variables, and the developer can assign them to other variables.
System Functions
System function is a predefined functionality along with parameters and returned value, that is handled by the system. All function names reflect their functionality. Some of the functions like “print” and “now” are of systemic nature, and their key is simply the functionality itself. For example, system function “now” returns a record that holds all current date and time data. Other functionalities are grouped by themes such as “io”, “math”, “string” and “storage”, and their key is in the format “theme.function”. For example, system function “string.section” gets parameters “text”, “from” and “length”, and returns a section of the string.
Using the system functions is done similar to user-defined functions, and the developer is calling the function with the respective parameters and uses the returned value if applicable.
As with regular functions, some of system function parameters can be omitted and the behavior and results will be accordingly. All code examples in the reference show the various options of using a function, including parameter’s omitting.
For example, using system function “storage.set”:
storage.set 'key' 'value'
storage.set 'key' 'othervalue' \f
storage.unset 'key'
storage.set 'key' 'othervalue' \f
The function gets three parameters: “key”, “value” and “anyway”, and sets Till storage “key” with value “value”. If “anyway” is TRUE, the “key” will be created or overwritten. If “anyway” is FALSE then, if the key exists its value will not be set, and if not exists it will be created. If “anyway” is omitted, the system will regard it as TRUE.
code analysis:
- set storage key “key” to value “value”
- since the key exists, do nothing (value will not be changed)
- delete key “key” from Till storage
- since the key does not exist, create it and set value to “othervalue”
As a conclusion to this chapter, here is program “math.sin” from the reference:
All system objects are shown in boldface in Till Launcher. In this program, system variables are “newline” and “math.pi”, and system functions are “print”, “math.sin” and “unicode”.
code analysis:
- set variable “angdeg” to 30
- variable “ang” get the result of: multiply “angdeg” by system variable “math.pi” value (π), divided by 180
- variable “m” get the result of applying system function “math.sin” over “ang”
- variable “degsym” get the result of system function “unicode” over the string “b0” (UNICODE hexadecimal value of degree symbol)
- apply system function “print” over the string summation of various scalar variables