as I've been browsing through `{NimDir}/lib/packages/docutils/rst.nim` today, 
I've seen this type syntax that's been new to me:
    
    
    Smilies = {
        ":D": "icon_e_biggrin",
        ":-D": "icon_e_biggrin",
        ":)": "icon_e_smile"
      }
    

that translates to `array[0..2, (string, string)]`

I only knew the (...) syntax to be used for tuples. I haven't been able to find 
anything about this in the docs.

as the usage in rst.nim kind of reminded me of associated arrays, or tables, 
dictionaries, or however you want to call them, I wonder, could I just use this 
type instead of hash tables?
    
    
    proc `[]` [T](s: seq[(string, T)], k: string): T =
        for key, val in s.items:
            if key == k:
                return val
    
    proc `[]=` [T](s: var seq[(string, T)], k: string, v: T) =
        for i in 0..s.high:
            if s[i][0] == k:
                s[i][1] = v
                return
        
        s.add((k, v))
    
    var map = @{
        "lerk": "ey",
        "lurk": "eey",
        "lork": "eeey"
    }
    
    echo map["lurk"] # eey
    map["lurk"] = "yee"
    echo map["lurk"] # yee
    

would that make sense if I just need string keys? what do you think would the 
performance vs hash tables look like?

Reply via email to