generic programming - How to get string representation of an expr in Nim template -


is there possibility string representation of expression (or identifier) inside template? example, having next code:

template `*`*(name: expr) {.immediate.} =   var `name`* {.inject.}: string = ""   # want print 'name' here, not value backticks 

is possible string representation of name expression inside template?

you can use asttostr magic system module this:

template foo*(name: untyped) =   var `name`* {.inject.}: string = ""   # want print 'name' here, not value backticks   echo "the variable name ", name.asttostr  foo test 

the output be:

the variable name test 

the use of immediate pragma discouraged latest version of compiler. see following answer more details: typed vs untyped vs expr vs stmt in templates , macros


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -