I know this code isn't meant to be used, but the given answers for `var Child`
were wrong to the point where I have to respond. We want the variable
`self.child` not `child`. No need for templates or anything
type
Child* = object
value: int
Parent* = object
child: Child
proc set_value*(self: var Child, value: int): var Child {.discardable.} =
self.value = value
self
proc get_child*(self: var Parent): var Child =
self.child = Child()
self.child
var parent = Parent()
parent.get_child().set_value(10)
echo parent.child.value # 10
Run
Again, this isn't idiomatic code, just had to point it out.