I'm trying to make a template that will declare a string whose contents comes from the untyped argument. As you can see, I'm constructing the string's identifier using the untyped argument, too; so it must remain untyped. Any ideas on how to do this? Here's the closest I can get:
template declareName*(name: untyped): untyped =
const `name Str`* {.inject.} = fmt"{name}"
declareName(Bob)
echo BobStr # desired output: Bob
Clarifying: my goal is not the output, nor declaring the const. I'm focused on whether a template can build a string from the untyped.
template declareName*(name: untyped): untyped =
const `name Str`* {.inject.} = astToStr(name)
declareName(Bob)
echo BobStr # desired output: Bob
Yes, that worked like a charm. Thank you!
(that one is not easy to find in the docs if you don't know what you're looking for)