Variables and Types
Declaring variables
Variables are declared with the var keyword, followed by a type and a name:
Every variable must be initialized when declared.
Reassignment
After a variable is declared, you can reassign it without the var keyword:
Types
CColon has eight built-in types:
int
64-bit signed integer.
| Property | Value |
|---|---|
| Size | 64 bits |
| Minimum value | -9,223,372,036,854,775,808 |
| Maximum value | 9,223,372,036,854,775,807 |
float
64-bit floating-point number (IEEE 754 double precision).
| Property | Value |
|---|---|
| Size | 64 bits |
| Precision | ~15 to 17 significant decimal digits |
| Minimum value | ~5.0 x 10^-324 |
| Maximum value | ~1.8 x 10^308 |
string
A sequence of characters, enclosed in double quotes.
Supported escape sequences:
| Escape | Character |
|---|---|
\n |
Newline |
\t |
Tab |
\\ |
Backslash |
\" |
Double quote |
bool
A boolean value, either true or false.
list
A dynamic, ordered collection of values. Lists can hold mixed types and grow or shrink at runtime.
See Lists and Arrays for more.
array
A fixed-size collection. Created with the fixed() function. Once created, the length cannot change.
See Lists and Arrays for more.
sint
Arbitrary precision integer with no size limit. Works like Python's int. Use this when you need numbers larger than what int can hold, or when you want to avoid overflow entirely.
Integer literals that are too large for 64-bit are automatically stored as sint. See sint for full details.
dict
A key-value mapping. Keys are strings, values can be any type.
See Dictionaries for more.
Constants
Use the const keyword to declare variables that cannot be reassigned:
Attempting to reassign a constant produces an error:
Constants work in both global and local scope. Local constants are checked at compile time, global constants at runtime.
Type conversions
Values can be converted between types using built-in methods:
var int n = 42
var string s = n.tostring() // "42"
var float f = n.tofloat() // 42.0
var string numStr = "123"
var int parsed = numStr.toint() // 123
var float pf = numStr.tofloat() // 123.0
var float x = 3.7
var int truncated = x.toint() // 3
See Methods on Values for the full list.