Objects
The language implements Objects, which can only contain primitive data types, with composite data types support planned for future versions. The following points define the semantics of objects and their conventions:
- Objects are allocated on the heap, allowing for efficient memory management
- Objects can be passed as arguments to functions, returned from functions, and assigned to each other if their types match
- The garbage collector manages memory allocation for objects, making it easier for manual memory management.
Declaration
#Declaring an object
#Initialization is mandatory while Declaring
obj o1 = {
int i = 10
};
fn start() void {
obj o2 = {
double d,
bool b
};
return;
}
Accessing and Updating an Element
fn start() void {
obj o2 = {
double d,
bool b
};
o2.d = 10.2;
bool c = o2.b | true;
return;
}
Passing and Returning Object Members
consume fn printint(int n) void;
fn one(obj: {int m, int n} my1) void {
printint(my1.m + 100);
printint(my1.n - 100);
return;
}
fn two() obj:{double , int } {
obj u = {
double d = 102.2,
int a = 111
};
return u;
}
fn start() void {
obj o1 = {
int d,
int b
};
one(o1);
obj o2 = two();
printint(o2.a);
return;
}