OK, this is not so important, but I still thing I'm missing something.
I want to create a const table (meaning: only for compile-time, in order to have things better organised). It's like that:
const
TABLE = {
"key1" : {
"param1": "a string",
"param2": 100
}.toTable(),
"key1" : {
"param1": "another string",
"param2": 200
}.toTable(),
...
}.toTable()
Quite obviously, the compiler complains about "param2" not being a (string,string) tuple.
How would I make this work? What do you suggest?
Note: it doesn't have to be a Table. It can be anything. All I want is a way to organize values by keys that are to be used solely at compile-time.
Use Nim's type system.
type
Keys = enum
key1, key2
Value = object
param1: string
param2: int
const
table = array[Keys, Value] = [
key1: Value(param1: "a string", param2: 100),
key2: Value(param1: "another string", param2: 200)
]
echo table[key2].param1
Maybe named tuples if they fit your case.
const
table = (
key1: (param1: "a string", param2: 100),
key2: (param1: "another string", param2: 200)
)
echo table.key1.param1 # a string