Hello,
i am playing with nimrod and got some question about object variants.
type
Node = object
case kind: NodeKind
of NodeKind.a, NodeKind.b:
var1: float
of NodeKind.b:
var2: float
No but you can do this:
type
Node = object
var1: float
case kind: NodeKind
of NodeKind.b:
var2: float
else: nil
The implementation compiles it to a C union.
Thank you for reply.
For my example it works this way. Now if I build something like a double linked list I would like to use the feature in the following way (middle will have next and prev):
type
NodePtr = ref Node
Node = object
case kind: NodeKind
of start, middle:
next: NodePtr
of end, middle:
prev: NodePtr
As I understand that is currently not possible. Would it make sense to extend the compiler to support this kind of construction? It seems to be usefull.