Skip to content

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

@oxinabox

Description

@oxinabox

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions