-
-
Save porterjamesj/7952882 to your computer and use it in GitHub Desktop.
some sort of threading macro
This file contains 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
function replace_(rep,expr::Expr) | |
i = findfirst(x->x==:_,expr.args) | |
if i == 0 | |
# recurse on subexprs one at a time | |
# subexprs = expr.args[] | |
error("dun goofed") | |
else | |
return Expr(expr.head, | |
[expr.args[1:i-1] | |
rep | |
expr.args[i+1:end]]...) | |
end | |
end | |
macro _(block) | |
valid = filter(x->typeof(x) != LineNumberNode && | |
(typeof(x) != Expr | |
|| x.head != :line),block.args) | |
foldl(replace_,valid) | |
end | |
@_ begin | |
3 | |
+(_,4) | |
_^2 | |
end # => 49 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment