Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Peaker
Created June 1, 2015 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Peaker/9e1d87e81945184871e4 to your computer and use it in GitHub Desktop.
Save Peaker/9e1d87e81945184871e4 to your computer and use it in GitHub Desktop.
Weird error about immutability
import tables, strutils
proc getFrequencies() : CountTable[string] =
let wordFrequencies = initCountTable[string]() # <-- this should be var
for line in open("example1.nim").lines():
for word in line.split(", "):
wordFrequencies.inc(word)
return wordFrequencies
let wordFrequencies = getFrequencies()
echo "The most frequent word is '", wordFrequencies.largest, "'"
echo "The frequencies are '", wordFrequencies, "'"
@Peaker
Copy link
Author

Peaker commented Jun 1, 2015

example1.nim(8, 22) Error: type mismatch: got (CountTable[system.string], string)
but expected one of:
system.inc(x: var T, y: int)
tables.inc(t: CountTableRef[inc.A], key: A, val: int)
tables.inc(t: var CountTable[inc.A], key: A, val: int)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment