I started using Verse and really struggle with the lack of functionality regarding parametric classes. We really need to be able to cast using parametric types and also the ability to declare variable member functions.
Here is an example case:
linked_list_node(t : type) := class<unique>:
Data : t
var Next : ?linked_list_node(t) = false
linked_list(t : type) := class:
var Head : ?linked_list_node(t) = false
var Tail : ?linked_list_node(t) = false
AddValue(Value : t) : void =
Print("Added")
DoSomethingWithList() : void =
if(var CurrentNode: linked_node(t) = Head?):
loop:
# Do something with CurrentNode.Data
if (set CurrentNode=CurrentNode.Next?):
else:
break
some_device := class(creative_device):
IntList: linked_list(int) = linked_list(int){}
FloatList: linked_list(float) = linked_list(float){}
AgentList: linked_list(agent) = linked_list(agent){}
This code above would work in an ideal world. It doesn’t tho.
Instead, we have to do this:
linked_list_node_base := class<unique>:
var Next : ?linked_list_node_base = false
linked_list_node(t : type) :=class(linked_list_node_base):
Data : t
linked_list_node_int := class(linked_list_node(int)){}
linked_list_node_float := class(linked_list_node(float)){}
linked_list_node_agent := class(linked_list_node(agent)){}
linked_list_base := class:
var Head: ?linked_list_node_base = false
var Tail: ?linked_list_node_base = false
linked_list_int:=class(linked_list_base):
AddValue(Value: int): void =
# ...
DoSomethingWithList() : void =
if(var CurrentNode: linked_node_base = Head?):
loop:
if(CurrentEventNode:= linked_list_node_int[CurrentNode]):
# Do something with CurrentEventNode.Data
if (set CurrentNode=CurrentNode.Next?):
else:
break
linked_list_float:=class(linked_list_base):
AddValue(Value: int): void =
# ...
DoSomethingWithList() : void =
if(var CurrentNode: linked_node_base = Head?):
loop:
if(CurrentEventNode:= linked_list_node_float[CurrentNode]):
# Do something with CurrentEventNode.Data
if (set CurrentNode=CurrentNode.Next?):
else:
break
linked_list_agent:=class(linked_list_base):
AddValue(Value: int): void =
# ...
DoSomethingWithList() : void =
if(var CurrentNode: linked_node_base = Head?):
loop:
if(CurrentEventNode:= linked_list_node_agent[CurrentNode]):
# Do something with CurrentEventNode.Data
if (set CurrentNode=CurrentNode.Next?):
else:
break
some_device := class(creative_device):
IntList: linked_list_int = linked_list_int{}
FloatList: linked_list_float = linked_list_float{}
AgentList: linked_list_agent = linked_list_agent{}
The example above is heavily simplified already and in practice, this is way worse than my minimum example. However i hope this makes clear how much those restrictions spaghettify the code and there is no way around it.
I really wish we might get some updates on parametric classes or at least get it put into the roadmap.
In my specific case, that i will not be able to show here, the lack of functionality lead to 900 additional lines of code, while this feature would have kept it doable in like 30 lines of code instead.