Literal Values
Integer Values
Integers are the backbone of XCS and are typically the most efficient data type. They can be trivially defined as such:
10
This would form the number 10 of type int, a flexible datatype that represents the most contextually-efficient integer size.
To elaborate, integers can be signed or unsigned, as well as sized (in bits). Signed integers can be positive or negative; unsigned integers can only be positive but range twice as high in value. It is considered best practice to use the smallest suitable integer size, because it will be the fastest in execution.
XCS offers Unsigned Integer values with the following ranges:
- 8-bit (u8): 0 -- 255 (2^8)
- 16-bit (u16): 0 -- 65,535 (2^16)
- 32-bit (u32): 0 -- 4,294,967,295 (2^32)
- 64-bit (u64): 0 -- 18,446,744,073,709,551,615 (2^64)
XCS offers Signed Integer values with the following ranges:
- 8-bit (i8): -128 -- 127
- 16-bit (i16): −32,768 -- 32,767
- 32-bit (i32): -2,147,483,648 -- 2,147,483,647
- 64-bit (i64): -9,223,372,036,854,775,808 -- 9,223,372,036,854,775,807
Arithmetic
For the purpose of demonstration, all literal arithmetic will result in the value: 8
Addition
4 + 4 -- Returns Sum of LEFT and RIGHT arguments (addition)
Subtraction
11 - 3 -- Returns Difference of LEFT and RIGHT arguments (subtraction)
Multiplication
4 * 2 -- Returns Product of LEFT and RIGHT arguments (multiplication)
Division (Quotient)
16 / 2 -- Returns Quotient of LEFT and RIGHT arguments (division)
Division (Remainder)
17 % 9 -- Returns remainder of LEFT and RIGHT arguments (division)
Bitwise Operations
For the purpose of demonstration, all bitwise arithmetic will result in the value: 8
Shift Bits Left
1 << 3 -- Shifts 1 LEFT 3 bits
Shift Bits Right
16 >> 1 -- Shifts 16 RIGHT 1 bits
Bitwise And
15 & 8 -- Performs Bitwise AND on arguments
Bitwise Or
8 | 0 -- Performs Bitwise OR on arguments
Bitwise Exclusive Or (Xor)
15 ^ 7 -- Performs Bitwise EXCLUSIVE OR on arguments
Real Values
XCSL offers two variations of Real Number values (e.g. numbers with decimal points):
- Single-Precision Floating Point (float): 7-8 digit precision
- Double-Precision Floating Point (double): 15-16 digit precision
Arithmetic
XCSL provides many of the same arithmetic operations as for integers.
Addition
4. + 4.5 -- Returns Sum of LEFT and RIGHT arguments (addition)
Subtraction
11 - 1.5 -- Returns Difference of LEFT and RIGHT arguments (subtraction)
Multiplication
3.14 * 2. -- Returns Product of LEFT and RIGHT arguments (multiplication)
Division (Quotient)
16. / 4.2 -- Returns Quotient of LEFT and RIGHT arguments (division)
Boolean Values
XCSL offers logical functionality in the form of Boolean values (True, False).
Constants and other named variables can typed as bool values, e.g.:
constant isConstant of bool = True
Logical operations always result in True
or False
. For demonstration purposes, the result of all literal operations will be True
.
Logical And
True && True -- Returns 'True' if both arguments are True
Logical Or
True || False -- Returns 'True' if either argument is True
Logical Xor
False ^^ True -- Returns 'True' if arguments are different
Less Than
3 < 5 -- Returns 'True' if LEFT arg. is less than RIGHT arg.
Less Than or Equal To
5 <= 5 -- Returns 'True' if LEFT arg. is less than or equal to RIGHT arg.
Greater Than
7 > 5 -- Returns 'True' if LEFT arg. is greater than RIGHT arg.
Greater Than or Equal To
6 >= 6 -- Returns 'True' if LEFT arg. is greater than or equal to RIGHT arg.
Equal To
False == False -- Returns 'True' if arguments are equivalent
1 == 1
Not Equal To
True != False -- Returns 'True' if arguments are not equivalent
1 != 2
Characters and Strings
XCSL provides two operators for defining ASCII literals:
- Single-Quotation Marks are used to define characters: 'A'
- Double-Quotation Marks are used to define strings: "Hello User!"
Escaped Characters
Special (Escaped) Characters can be defined using the backslash ('') character.
See the following list of escaped characters:
- New-Line: '\n'
- Tab Character: '\t'
Containers
Linked Lists
Linked Lists are the standard containers for collections of like-type data on XCS. They provide quick and easy ways to define and reference lists of numbers, letters, phrases, etc.
See below as an example, a constructed list of integers:
1 :: [2, 3, 4, 5]
This example list would include 5 elements, starting with 1 and ending with 5.
For purpose of demonstration, each string operation will result in "Hello User!".
Construction
'H' :: "ello User!" -- Builds a list from head and tail arguments
Head / Tail
hd ["Hello User!", "Goodbye User!"] -- Returns first element of a list (head)
tl "0Hello User!" -- Returns a new list without head (tail)
Concatenation
"Hello " ++ "User!" -- Builds a new string from right/left arguments
Length
You can determine the (integer) length of a list using len
, as such:
len [0, 1, 2] -- Would return: 3
Arrays
Arrays are similar to Linked Lists, except array entries are concatenated in memory (linked list entries are scattered in memory and dynamically linked).
Tuples
Tuples are containers for collections of mixed-type data on XCS. Unlike other containers, each tuple element's type expression can be independent of other elements' types.
See below for a tuple example:
let odd = 1 ; "hello" ; 3.14;;
odd.{0};; -- Returns 1
odd.{1};; -- Returns "hello"
odd.{2} -- Returns 3.14