I am a novice in nim and don't know much about the type system. I went through
the documentation and found this out
> All expressions have a type which is known at compile time. Nim is statically
> typed.
Is there any way I can create typed variables at runtime? Here is what I am
trying to achieve. I get a JSON from the client which gives me the type and
value, both as strings as shown below.
"args":[
{
"value":"1",
"type":"int"
}
]
I would like to create a variable of the type specified by the "type" field in
the JSON and convert the value specified by the "value" field in the JSON to
the type specified in the JSON. I was thinking of a function which converts
this JSON to a variable and returns it to me as shown below.
proc getArg(typeName:string, strValue:string):XXXXX=
case typeName:
of "string":
result = strValue
of "int":
result = parseInt(strValue)
As you can see the return type of the function is set to XXXX as I didn't know
what it actually should be. I read about macros and templates and found out
that both of them operate at compile time and not run time. What is the best
way to achieve this? Or is this not possible?