I'm trying to simplify my program syntax by creating nice aliases. Cannot 
understand what's wrong when returning var t where t is typedesc:
    
    
    import tables
    
    proc getTableOf*(t: typedesc): ref Table[int, t] =
      var table {.global.} = newTable[int, t]()
      return table
    
    proc getVal(key: int, t: typedesc): t =  # just an easy accessor (alias)
      getTableOf(t)[key]
    
    # check they are the same
    getTableOf(bool)[0] = false
    assert 0.getVal(bool) == getTableOf(bool)[0]  # for key "0", lookup value 
in boolean table - this works
    echo "ok"
    
    
    proc getMutableVal(key: int, t: typedesc): var t =
      getTableOf(t)[key]
    
    getTableOf(bool)[0] = false  # get boolean table, select mutable value by 
key - this works!
    0.getMutableVal(bool) = false  # same: for key "0", get mutable value from 
boolean table
    # ^-- Error: type mismatch: got <bool> but expected 'None'
    assert 0.getVal(bool) == false
    echo "ok"
    

Please help! :/

Reply via email to