-
Notifications
You must be signed in to change notification settings - Fork 0
Variables
Kode is both an interpreted and strongly-typed language. For the most recent version, variables are only sequentially created in memory when first encountered in the script. Furthermore, their type must be declared and preserved throughout their lifecycle. For example, declaring a string variable would look as follow:
string hello = "Hello World!"
Using the same declaration syntax, Kode also supports the following primitive types:
Type | Description |
---|---|
int | Integer (64-bits) |
float | Floating-point number (64-bits) |
string | A string containing a sequence of characters |
bool | Boolean value |
func | Function object containing other variables and functions |
null | Null object |
Although the type of the variable must be explicitly declared at the beginning of the declaration, the keyword val
can be used in the declaration type instead to automatically access the type of the provided value. For example,
val myVariable = "Hello World!"
is equivalent to
string myVariable = "Hello World!"
Modifying the value of a variable with another value of the same type is straightforward as follows:
string myVariable = "Hello World!"
myVariable = "Hello again world!"
Unfortunately, in order to create a type-safe system, Kode does not allow by default to change the variable type after its declaration, as previously shown. In order to change the type of a variable, :=
must be used instead of =
to essentially inform Kode to ignore the previous type of the variable. For example,
string myVariable = "Hello World!"
myVariable := 10