This isn't nearly as sophisticated, but you can do something like this with a 
regular getter/setter too. It won't work for a plain variable, but if it makes 
sense to tie it to an object, you can do this:
    
    
    # robots.nim
    type
      Robot* = object
        name: string
    
    proc `name=`*(self: var Robot, name: string) =
      self.name = name
      echo "Robot name has been changed"
    
    proc name*(self: Robot): string = self.name
    
    # main.nim
    import robots
    
    var robot = Robot()
    robot.name = "Dave"
    echo "Our robot is named ", robot.name
    
    
    Run

Reply via email to