I have a table in a separate file a.nim
import std/tables
let
lookupTestTable* = {
"A1": """ 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
1 1 0 0 0 0 0 0
0 1 0 0 0 0 0 0""",
"B1": """ 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
1 1 1 0 0 0 0 0
1 0 1 0 0 0 0 0"""}.toTable
I want to use that table in another file b.nim.
But when I import it, It seems to change behavour. If I print the table in its file (a.nim), I get the correct output
{"B1": " 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0\n 1 1 1 0 0 0 0 0\n 1 0 1 0 0 0 0 0", "A1": " 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0\n 1 1 0 0 0 0 0 0\n 0 1 0 0 0 0 0 0"}
But, when I import it into b.nim, I can't access it's value's by the key. e.g lookupTestTable["B1"]
I get this strange error
Error: type mismatch: got <Table[system.string, system.string], string>
but expected one of:
proc `[]`(s: string; i: BackwardsIndex): char
first type mismatch at position: 0
proc `[]`(s: var string; i: BackwardsIndex): var char
first type mismatch at position: 0
proc `[]`[I: Ordinal; T](a: T; i: I): T
first type mismatch at position: 0
proc `[]`[Idx, T; U, V: Ordinal](a: array[Idx, T]; x: HSlice[U, V]): seq[T]
first type mismatch at position: 0
proc `[]`[Idx, T](a: array[Idx, T]; i: BackwardsIndex): T
first type mismatch at position: 0
proc `[]`[Idx, T](a: var array[Idx, T]; i: BackwardsIndex): var T
first type mismatch at position: 0
proc `[]`[T, U: Ordinal](s: string; x: HSlice[T, U]): string
first type mismatch at position: 0
proc `[]`[T; U, V: Ordinal](s: openArray[T]; x: HSlice[U, V]): seq[T]
first type mismatch at position: 0
proc `[]`[T](s: openArray[T]; i: BackwardsIndex): T
first type mismatch at position: 0
proc `[]`[T](s: var openArray[T]; i: BackwardsIndex): var T
first type mismatch at position: 0
template `[]`(s: string; i: int): char
first type mismatch at position: 0
expression: `[]`(lookupTestTable, "A1")
When I print what is inside the table (in b.nim), this is the output
(data: @[(hcode: 0, key: "", val: ""), (hcode: 2437449353, key: "B1", val: " 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0\n 1 1 1 0 0 0 0 0\n 1 0 1 0 0 0 0 0"), (hcode: 0, key: "", val: ""), (hcode: 0, key: "", val: ""), (hcode: 0, key: "", val: ""), (hcode: 3101379309, key: "A1", val: " 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0\n 1 1 0 0 0 0 0 0\n 0 1 0 0 0 0 0 0"), (hcode: 0, key: "", val: ""), (hcode: 0, key: "", val: "")], counter: 2)
What is causing this weird behavour? I've tried changing it to const, var , still the same behavour