Re:Porting a NES Emulator from Go to Nim
by beagle3 on Sunday May 03, 2015 @09:33AM
(#9481205)
Thanks. I'm sure there's a way to promote a compile time seq into a constant runtime one. Might require some more macro trickery, though.
[ Parent
| on HN ]
Err... what you said just reminded me of something, and I realized all the code I just showed you is really over-complicated and that Nim has much more straight forward options using `const`, like this:
static:
# define a compile-time list first
var names = newSeq[string]()
# add some values (at compile-time)
names.add("foo")
names.add("bar")
# define the compiler vars as run-time const
const runtimeNames = names
# define some run-time variables
var name1 = "foo"
var name2 = "blah"
# check runtime variables against const variable
if runtimeNames.contains(name1): echo "Has Foo!"
if runtimeNames.contains(name2): echo "Has Blah!"
Sorry about the rather winded (and bad example) replys :| But thanks for the conversation, it reminded me of this and now I have some cleaning up of my own code to get too. Cheers!