working solution all in one snippet 
    
    
    type
      Child* = ref object
        value: int
      
      Parent* = ref object
        child: Child
    
    
    proc set_value*(self: var Child, value: int): var Child {.discardable.} =
      self.value = value
      return self
    
    proc return_child(child : var Child) : var Child {.discardable.} =
      child
    
    template get_child*(self : var Parent) : Child =
      var child = Child()
      self.child = child
      return_child(child)
    
    
    
    
    var parent = Parent()
    
    parent.get_child().set_value(10)
    
    
    Run

However I would use @mratsim's solution instead unless you are using objects 
instead of ref objects.

Reply via email to