Skip to content

Instantly share code, notes, and snippets.

@porterjamesj
Last active December 31, 2015 07:19
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 porterjamesj/7952882 to your computer and use it in GitHub Desktop.
Save porterjamesj/7952882 to your computer and use it in GitHub Desktop.
some sort of threading macro
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