Difference between other languages and ReGIna is dynamic
instantiation. In short, properties in classes will be assigned only
after their dependencies are assigned, allowing recursive properties of
same class A
inside class A
.
Classes can have references to other classes inside them as properties. These property-classes are evaluated dynamically. Take a look at this example:
class Node export rect {
// export = false - can deny export
= if (parent) parent.iter + 1 else 0
iter
= if (iter == 5) Nothing() else Node()
childNode
= if (childNode is Node) \
position (childNode.position.x + 1, childNode.position.y) \
Positionelse Position(0, 0)
}
fun main() {
()
Node}
This will create following svg:
svg>
<rect x="4" y="0"/>
<rect x="3" y="0"/>
<rect x="2" y="0"/>
<rect x="1" y="0"/>
<rect x="0" y="0"/>
<svg> </
First algorithm creates empty Node() (we’ll call it Node0) from main(). Then, starting from top to bottom:
It’s not important to consider while assigning values, but it shows why there cannot be any cyclic dependencies for properties.
class FunctionOveruse {
= make()
prop
fun make() {
()
FunctionOverusereturn prop
}
}
Both lines in make()
will execute forever.
To make functions as expressive as possible, it is important to allow class instantiating inside them. If
We either make internal class functions (which is purely
decompositional thing) or make instantiating inside functions possible
(and fun main()
as an entry point)