tquotewords.nim 411 B

1234567891011121314151617181920212223
  1. discard """
  2. output: "thisanexample"
  3. """
  4. # Test an idea I recently had:
  5. import macros
  6. macro quoteWords(n: varargs[untyped]): untyped =
  7. let n = callsite()
  8. result = newNimNode(nnkBracket, n)
  9. for i in 1..n.len-1:
  10. expectKind(n[i], nnkIdent)
  11. result.add(toStrLit(n[i]))
  12. const
  13. myWordList = quoteWords(this, an, example)
  14. var s = ""
  15. for w in items(myWordList):
  16. s.add(w)
  17. echo s #OUT thisanexample