Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Variables

Variable declarations are extremely simple. Simply pick a variable type and identifier, then set it to a value.

int x = 20;

Note

You cannot defined a variable with no value, for example: int x; is not valid syntax. However, variables are treated as mutable, so to achieve the same effect just initialize the variable with dummy data.

Currently the supported types in KSL are:

TypeIdentifierSize (Bits)Size (Bytes)
int8i881
int16i16162
int32i32324
int64i64 || int648
uint8u881
uint16u16162
uint32u32324
uint64u64 || uint648
float32f32324
floatf64 || float648
charchar81
boolbool11
voidvoidN|AN|A
enumenum????
structstruct????

Note

You can make virtually any type an array by adding [] to the initialization type (e.g. int[] will create an int array.)

Note

Defining structs via the struct keyword will register an entierly new type to the type system, it can be treated like most other types, which means you can also make an array of structs using the struct name (e.g. my_struct[] will create an array of my_struct structs.)

KSL supports variable shadowing, so you can use multiple variables with the same name as long as they don’t cross scopes. For example:

using std.io;

fn main() -> void {
	int i = 400;

	if (true) {
		int i = 30;
		io.writeln(i); // will write 30 to console
	}

	io.writeln(i); // will write 400 to console
}