Created
June 1, 2015 19:24
-
-
Save Peaker/9e1d87e81945184871e4 to your computer and use it in GitHub Desktop.
Weird error about immutability
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, "'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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)