Datatypes
As previously shown in the docs page Variables, every variable always has a type that defines what values it can store. This also means that you often can not mix variables of different data types together, as they fundamentally represent different things.
What is a datatype?
A data type defines the type of value, which can be stored in a variable or constant.
A variable with the datatype num
, for example, can only contain numbers. A variable
with an str
datatype can only contain text, symbols or numbers, but saves them as text.
This makes them for example impossible to use for calculations and as such using them in arithmetic
expression is invalid.
Important
Data types can not be mixed together and must be converted before being used with another type.
✓ VALID CODE
X INVALID CODE
List of data types in Kipper
Number Type - num
Represents a number (both floating point and integer) in the Kipper language. This datatype may always be used with the standard mathematical expressions.
Examples
Important
Remember that Kipper will interpret mathematical calculations as defined in the standard math conventions. (Multiplications, divisions and power-to operations have a higher priority than additions and subtractions.)
Additionally, to the default Base-10 numbers, you may also use Hex, Octal and Binary numbers:
String Type - str
A string is a simple sequence of characters in UTF-16. A string may be any length, as underneath the length of the list that represents the string will always be increased as needed.
Examples
Strings are defined using quotation marks (""
) , which automatically hint the
str
type.
Char Type - char
Removed starting with v0.10.0
A character is a simple UTF-16 character, which may represent any Unicode character that is defined
in the UTF-16 standard. To define a simple character, you use the ''
syntax, hinting a
single character.
Examples
Boolean Type - bool
The boolean is a simple binary value that may be either true
or false
.
The value can be also represented as 0 (false
) and 1 (true
).
Examples
Void Type - void
The void
type represents a value that is nothing and may only be void
.
This is usually used for functions to hint they have no return. Otherwise, this data type is practically useless, and it should be not be used.
Examples
List Type - list<type>
Scheduled for release in Kipper v0.12.0
The list<type>
data type is a unique data type, as it does not represent itself a
value, but rather a sequence of multiple values. As a result of that a list has also a length and an
index for each item, which you may use to access them using the following syntax: