Skip to content

Instantly share code, notes, and snippets.

@flyx
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flyx/46b34c8acceb99e94ee3 to your computer and use it in GitHub Desktop.
Save flyx/46b34c8acceb99e94ee3 to your computer and use it in GitHub Desktop.
import macros
macro callFilter(filter: stmt, value: stmt): expr =
if value.kind == nnkStrLit:
newStmtList(
newNimNode(nnkConstSection).add(newNimNode(nnkConstDef).add(newIdentNode("filtered"), newEmptyNode(),
newCall(filter, value))),
newIdentNode("filtered"))
else:
newCall(filter, value)
proc filterStuff(bla: string): string =
"dummyFilter: " & bla
echo callFilter(filterStuff, "test1")
let test2 = "test2"
echo callFilter(filterStuff, test2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment