When doing manual memory management in Nim, I often find myself having to 
define two versions of a proc - one that takes a `var` parameter and one that 
takes a `ptr` parameter.

Otherwise I will run into issues like this:
    
    
    var m: ptr Monster
    var b: Bullet
    
    proc chooseAnim(m: var Monster) =
      # some logic to set the current animation
      # ...
    
    proc update(b: ptr Bullet) =
      # move the bullet and check for collisions
      # ...
    
    m.chooseAnim()  # uh oh!
    m[].chooseAnim()  # better.
    
    b.update()     # uh oh!
    (addr b).update()  # better.
    
    
    Run

I was happy to discover that [{.experimental: 
"implicitDeref".}](https://nim-lang.org/docs/manual.html#types-reference-and-pointer-types)
 is a thing, which pretty much fixes all my problems! If I define the `var` 
version of the procedure, I don't need to define the `ptr` version anymore.

But I suppose I can't start doing this in library code yet, because then I'd be 
forcing other people to use this experimental pragma in their code, or to have 
to worry about addressing/dereferencing their stuff to make the library 
functions happy.

So I was wondering, what's the future of this feature? Do we know yet if it's 
here to stay? Does it have any caveats that I should know about?

Thanks :)

Reply via email to