Hello,
I would like to create a tuple dynamically at runtime. Is this possible?
I will have strings, types, and values. But not until runtime when all the data is assembled. I don't even necessarily care about the names, but it is nice. But I do need a heterogeneous data structure.
So how would I create from dynamic data?
Any help greatly appreciated.
type
Person = tuple
name: string
age: int
assert (1, 2, 3) is tuple
🤔?Tuples like arrays are defined in Nim at compile time, you can not use tuples when you do not know the number and typed of the fields at compile time.
You may use a seq, with entries of type ref rootref, and make all your types subclass of ref rootref (or of a other common parent class).
Or you may use sum types called object variants in Nim, as seq elements.
Or maybe, you could be interested in module https://github.com/yglukhov/variant.
You may be also interested in the JSON module.
I was not sure if there were a way or not. Tuple is what I want for production code. By then I will know all the details. During exploration and experimenting JSON will work fine.
Thanks for the information and suggestion. The link was educational.