I'm learning Nim (previously used Python and C++/etc.) and trying to attempt 
[https://adventofcode.com/2018/day/2](https://adventofcode.com/2018/day/2).

I'm using a CountTable to count how many times each character appears:
    
    
    for line in f.lines:
      if line.len == 0: break
      var cnts = CountTable[char]()
      for c in line:
        cnts.inc(c)
    
    
    Run

  * Is there an editor (vscode/pycharm/sublime/etc.) plugin, or `nim compile` 
mode to show the inferred types of local variables? I was a bit confused but 
apparently `line` is a `TaintedString` and `c` is a `char` (since changing to 
`CountTable[int]()` doesn't compile).
  * The documentation for `CountTable` is autogenerated and lacking (no 
"description" explaining how to use CountTable). I found a forum thread 
([https://forum.nim-lang.org/t/3432](https://forum.nim-lang.org/t/3432)) saying 
you can just call `CountTable.inc(obj)`. And the source code for `inc()` 
apparently inserts the element if it's not already present. However doing that 
in my code results in error:


    
    
    d2.nim(23)               d2
    tables.nim(1004)         inc
    system.nim(414)          rawGet
    system.nim(2830)         sysFatal
    Error: unhandled exception: index out of bounds [IndexError]
    
    
    Run

Version: kubuntu 18.04:
    
    
    ~ ❯❯❯ nim
    Nim Compiler Version 0.19.0 [Linux: amd64]
    Compiled at 2018-09-26
    Copyright (c) 2006-2018 by Andreas Rumpf
    
    
    Run

Reply via email to