Last active
August 29, 2015 14:18
-
-
Save flyx/46b34c8acceb99e94ee3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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