Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sourcewalk (etc) drops all but the first character in replacements #122

Open
oxinabox opened this issue Aug 22, 2019 · 0 comments
Open

sourcewalk (etc) drops all but the first character in replacements #122

oxinabox opened this issue Aug 22, 2019 · 0 comments

Comments

@oxinabox
Copy link
Member

This is hard to explain.
here is a demo

I want to remove the second argument of a 3 argument function.

julia> using MacroTools: textwalk

julia> code = """
           test_scalar(cos, x -> -sin(x), x)
           test_scalar(tan, x -> 1 + tan(x)^2, x)
           test_scalar(sec, x -> sec(x) * tan(x), x)
           test_scalar(csc, x -> -csc(x) * cot(x), x)
           """;

julia> function twoarg(expr)
       @capture(expr, t_(f_, d_, x_)) && t==:test_scalar && return :(test_scalar($(f), $x))
       return expr
       end
twoarg (generic function with 1 method)

julia> textwalk(twoarg, code) |> println
test_scalar(c, x)
test_scalar(t, x)
test_scalar(s, x)
test_scalar(c, x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant