auto- Type inferencedynamic- Dynamic type (primitive) (heap allocated)fun- Declares a dynamic function, can be used with static return type functions too- [DEPRECATED]
hoist- Hoists a variable to the top of its scope. Defines at the normal point unsigned- Makes a number variable unsignedsigned- Makes a number variable signedclass- Makes a classstruct- Makes a structunsafe- Creates a block where you can use unsafe functionsnew- New keyword, used when creating objects
Class Scopes
public- Class public scopeprotected- Class protected scopeprivate- Class private scopeprivatew- Class privatew scope (only private scope can write, everyone can read)protectedw- Class protectedw scope (only protected/private scope can write, everyone can read
Imports
import- Imports a fileimport java- Imports a java class(must be compiled to JVM or have a JVM it can reference to)extern "C"- Creates a block where you can declare C functions, must be in an unsafe blockpackage- Sets a package, needed when compiling to JVM or integrating with java
Built-in types
Number Types
short- 2 byte integerint- 4 byte integerlong- 8 byte integerbyte- 1 byte integerfloat- 4 byte decimal numberdouble- 8 byte decimal numberdynamic- heap allocated dynamic data type
Other primitive Types
string- A string !! Not aclassfreeobj- A JavaScript like object that can store data, functions, etc. If it can be lowered to a structure it will be to save on heap memory and overhead- [DEPRECATED]
Number- A JS like number that supports decimals and whole numbers up to 8 bytesBigInt- A JS like dynamically allocated integer, up to 32 bytesBigNumber- A dynamically allocated number that can support numbers up to 32 bytes
//Easiest way
auto dynamic = { //inferred as freeobj
name: "Zenith",
version: 1.0f,
getInfo: () => "${this.name} v${this.version}"
}
//Redundant freeobj way
auto dynamic = freeobj {
name: "Zenith",
version: 1.0f,
getInfo: () => "${this.name} v${this.version}"
}
//Type strict way
freeobj dynamic = freeobj { //second freeobj Infront of { is optional
name: "Zenith",
version: 1.0f,
getInfo: () => `"${this.name} v${this.version}"`
}
//Edge cases
struct somestruct{...}
somestruct name = {} //will be a struct
somestruct nicename = freeobj {} //Type conversion error as you are specifically making a freeobject but assigning it to a structure yype
Built-in class types
IO- simple console and file IO- Std lib not done
Functions
fun type name(type argName){}
Loops
forloop
for(let i=0;i<123;i++){
//
}
int arr[1024] = ...
for(int i : arr){
//Log i
}
whileloop
while(somecondition){
//
}
do-whileloop
do {
//
}
while (condition)
If statements
if(condition){
//do this
}else{
//do that
}
if(condition){
//do 1
}else if(condition){
//do 2
}
Objects
Classes
class Cat{
privatew string name;
privatew double age // ; optional
public void pet(){
IO.print(`"${this.name} feels very Loved!"`)
}
public void age(double age){
if(age>0){
this.age+=age
}
}
public Cat(string name, Gender gender){
this.name = name
this.age = 0
}
}
Structs
struct Vector3{
int x;
int y;
int z;
}
[DEPRECATED] Union
union Pet{
Cat;
Dog;
}
- Annotations can be added to anything and hold some extra info, work the same as Java Annotations can hold anything, they give runtime metadata(in some cases with the built-in ones it's compile time)
@Breedable
class Cat{...}
@Register(id="some_registry_entry",registry="block")
class Cube{...}
@NotNull
let somevarthatcantbenull = 1
@IsAGreatFunction
fun givesGreatResponses{...}
- Decorators - can be added to functions/methods and function as a wrapper before executing the main code
@@Memoize
fun fibbonaci(){}
Annotations
annotation ComesFromNet
@ComesFromNet
/************************/
annotation Name{
string value;
}
@Name("John Cena")
/************************/
annotation Register{
string registry;
string id;
}
@Register(id="actor",registry="con")
/************************/
annotation Register{
string registry;
Cat mother;
}
Decorators
[WIP]
Classes
Classes are the foundation of OOP, encapsulating data (fields) and behavior (methods). They support:
-
Inheritance
-
Operator overloading (though not shown in this first example)
-
Automatic getters/setters (though not shown in this first example)
-
Constructors, destructors, and method overriding
Key Modifiers
const– Makes a field immutable (must be initialized at declaration or in the constructor).static- Makes the member not need an instance to be accessed
class Dog {
// Fields with restricted write access
privatew double age;
protectedw string breed;
const public string name;
public Dog(string name, string breed) : name(name) {
this.age = 0;
this.breed = breed;
}
public void describe() {
IO.print(`"${this.name} is a ${this.breed} aged ${this.age}."`);
this.age = 5
}
// Protected method (can modify protected fields)
protected void setBreed(string newBreed) {
this.breed = newBreed;
}
}
class Mallinois : Dog {
public Mallinois(string name) : Dog(name, "Mallinois") {}
public void train() {
this.age = 3;
this.breed = "Trained Mallinois";
IO.print(`"${super.name} is now a ${this.breed}!"`);
}
}
// Example Usage
fun main() {
Dog buddy = new Dog("Buddy", "Labrador");
buddy.describe(); // "Buddy is a Labrador aged 0."
// Can READ but NOT WRITE privatew/protectedw from public scope:
// buddy.age = 5; // ERROR: privatew write outside class!
// buddy.breed = "Poodle"; // ERROR: protectedw write outside hierarchy!
Mallinois rex = new Mallinois("Rex");
rex.train(); // "Rex is now a Trained Mallinois!"
rex.describe(); // "Rex is a Trained Mallinois aged 0."
}
class Vector3D {
// Private fields (readable everywhere, writable only in Vector3D)
privatew double x;
privatew double y;
privatew double z;
// Constructor
public Vector3D(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
}
// --- Setters (with validation) ---
public void setter(x) setX(double x) {
if (!x.isNaN()) { // Example validation
this.x = x;
}
}
// (Similar for setY/setZ...)
// --- Operator Overloading ---
// Vector addition (+)
public Vector3D operator+(Vector3D other) {
return new Vector3D(
this.x + other.x,
this.y + other.y,
this.z + other.z
);
}
// Scalar multiplication (*)
public Vector3D operator*(double scalar) {
return new Vector3D(
this.x * scalar,
this.y * scalar,
this.z * scalar
);
}
// Equality check (==)
public bool operator==(Vector3D other) {
return this.x == other.x
&& this.y == other.y
&& this.z == other.z;
}
// --- String representation ---
public string toString() {
return `"(${this.x}, ${this.y}, ${this.z})"`;
}
}
// Example Usage
fun main() {
Vector3D v1 = new Vector3D(1.0, 2.0, 3.0);
Vector3D v2 = new Vector3D(4.0, 5.0, 6.0);
// Operator overloading
Vector3D sum = v1 + v2; // (5.0, 7.0, 9.0)
Vector3D scaled = v1 * 2.0; // (2.0, 4.0, 6.0)
bool isEqual = (v1 == v2); // false
// Getters/setters
IO.print(v1.getX()); // 1.0
v1.x = 10.0; // Valid write ↓
// v1.x = 10.0; // Usually would error, but will automatically use setter, ERROR: privatew write outside class!
IO.print(sum.toString()); // "(5.0, 7.0, 9.0)"
}
Structs
- Structs are the same as classes, but have a default access level of public
struct Vector3{
public int x;
public int y;
public int z;
//By default they don't have a constuctor
}
Vector3 a = {1,2,4}
Vector b = {
a: 1,
b: 2,
c: 4
}
[DEPRECATED] Union
- A union is a special data type that lets you store different types of data in the same memory space, but only one at a time Key Idea:
- Unlike a struct (where each field has its own memory), a union shares the same memory for all its fields
- Changing one field overwrites the others
- Size = largest member’s size (since memory is shared)
- Do not directly support dynamic variables
- If they contain an object that contains dynamic variables they will be ignored (in size)
- No way to know what type is active
union arbnum {
int,
float
}
enum ReadFileRV {
SUCCESS(data: string)
ERR_NO_ACCESS,
ERR_IN_USE
}
Used with
match value{
SUCCESS => {
//LAMBDA
}
//etc...
}
path
|> readFile
|> fileType
|> match {
XML |> parseXml |> docFromXml
JSON |> parseJson |> docFromJson
_ |=> {/*lambda*/ IO.print("wrong type")} |> break //breaks parent lambda
}
|> modifyDoc
|> saveDoc(path, _) //_ is result from previous