Anrgentum objects can be turned immutable with prefix freeze operator "*".
class Point {
x = 0;
y = 0;
set(x int, y int) this { this.x := x; this.y := y; }
}
p = *Point.set(10, 42);
// now point p is immutable
p.x += 1; // compilation error, `p` is *Point, and cannot be modified.
Immutable objects are shared across object hierarchies and threads.
There can be declared a methods, specifically callable to immutable objects and methods that cam be called on any objects - regardless their mutable status:
class Node {
name = "";
chilren = Array;
-isLeaf() bool { children.size() == 0 }
}
// method `isLeaf` can be called on any Node - frozen or not
Frozen pointers can reference one object from different other objects. They represent the "aggregation" relationships in terms of UML. With adding of this mechanism Argentum now supports all UML object relations:
- Composition with unique "@pointers" to mutable objects
- Aggregation with shared "*pointers" to immutable objects
- Association with non owning "&pointers".
Details are here: http://aglang.org/.....shared-pointers-to-immutable-objects
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.