In this example, how can I call test macro with sequence generated in compile time?
import macros, future
macro test(xs: static[seq[string]]): stmt =
result = newStmtList()
for x in xs:
let st = quote do:
echo `x`
result.add(st)
proc getSeq(): seq[string] {.compileTime.} =
lc[$x | (x <- 0..100), string]
when isMainModule:
test(@["1", "2", "3"])
test(getSeq())
This version of getSeq works:
proc getSeq(): seq[string] {.compileTime.} =
result = toSeq(0..100).mapIt(string, $it)
And this don't:
proc getSeq(): seq[string] {.compileTime.} =
result = toSeq(0..100).map(proc(x: int): string = $x)
This version:
proc getSeq(): seq[string] {.compileTime.} =
result = toSeq(0..100).map(x => $x)
produces error cannot evaluate at compile time: x