Hi All!
could you please look on it:
import macros
macro testM(): untyped =
let smbl = nskLet.genSym("testLet")
echo smbl.symbol.getImpl.strVal #comple time error: field 'strVal' cannot be found
testM()
Why error? How can I get an unique fresh symbol at compile time?
Thanks
I'm guessing what you want is to get the unique identifier, for which you can use the repr proc on a symbol.
import macros
macro test: untyped =
let smbl = nskLet.genSym("testLet")
let identifier = repr(smbl) # or repr(smbl.symbol)
echo identifier
test
getImpl only works for consts or proc/method/converters, it returns the node of the thing the symbol is referring to. For example,
import macros
proc foo(a, b: int): int = a + b
macro test: untyped =
# bindSym gets a symbol from the codebase. brClosed gets it from where the macro is defined, brOpen gets it from where the macro is called
let fooNode = bindSym("foo", brClosed)
echo repr(fooNode.symbol.getImpl) # this will pretty print the AST of foo
test
Wow, repr of type NimNode or NimSym. That is nice! I didn't know it.
Thanks a lot!