> Another way to address both is to have a new 2-body template (I called this 
> editOrInit in adix/lptabz.nim)

there's already `tables.withValue` which I think is what you're describing but 
it's less flexible than the proposed `getPtr` from 
<https://github.com/nim-lang/Nim/pull/18253>, eg see 
<https://github.com/nim-lang/Nim/pull/18253#issuecomment-860483037>, or at 
least it's cumbersome to use with the same effect:
    
    
    when true:
      # with withValue:
      let val2 = block:
        var tmp: ptr string
        t.withValue("foo1", val): tmp = val
        tmp
      echo val2[]
      
      # with getPtr:
      let val3 = t.getPtr("foo1")
    
    
    Run

(note that withValue also returns a ptr, and, although it's by default scoped 
inside the template body, it still has same caveats as getPtr if the template 
body involves table mutations) 

Reply via email to