Other Primitive Types
Abstract also has some other primitive types that aren't just numbers. Some of them exists to create some abstractions with complex collections of numerical values or create type encapsulation.
Booleans
Booleans are types that can only represent the binary values true
or false
.
These two values are extremely important to handle conditionals or hold simple
states without messing the values.
Alias | Size | Implementation |
---|---|---|
bool | 8 bits / 1 byte | Std.Types.Boolean |
let bool cake = false
if (cake) Std.Console.writeln("Yummy!")
else Std.Console.writeln("The cake is a lie!")
The cake is a lie!
Strings
A string is a data structure that is able to store text data. A string can be
used to store and reproduce text characters easily.
In Abstract, every string is encoded in UTF-8, with characters varying from 1-4
bytes in length.
Alias | Size | Implementation |
---|---|---|
string | variable (heap allocated content) | Std.Types.String |
let string mySpeek = "Hello, World!"
Std.Console.log(mySpeek)
mySpeek = "Goodbie, World!"
Std.Console.log(mySpeek)
Hello, World!
Goodbie, World!
Chars
Chars are data structures made to hold a single text character. Chars value can
either be set or assigned manually with a character value or it can be set by
getting a character from an index of a string.
As every string in Abstract is UTF-8, every character have the same length as a i32
in memory, being able to hold every possible character of the Unicode char set.
Alias | Size | Implementation |
---|---|---|
char | 32 bits / 4 bytes | Std.Types.Character |
const string myString = "Hello, World!"
let char myChar = 'U'
myChar = myString[7] # 'W'