Yes wish tables were more intuitive. Maybe the correct term is associative 
array. It can sort of made easy with some init setup. This for a two key table, 
same idea for any table size or type
    
    
    type
      TwoKeyTable* = Table[string, Table[string, string]]
    
    proc initTwoKeyTable(): TwoKeyTable =
      result = initTable[string, Table[string, string]](1)
    
    proc addKeyPairValue[T](tkTable: var TwoKeyTable, k1, k2: string, val: T) =
      if not tkTable.hasKey(k1):
        tkTable[k1] = initTable[string, string](1)
      tkTable[k1][k2] = val
    
    var
      booksTable = initTwoKeyTable()
    
    
    Run

Now it's setup, to add to the table: 
    
    
    addKeyPairValue(booksTable, "key1 name", "key2 name, "value" )
    
    
    Run

Reply via email to