Expression Updating

I would suggest to use MacroTools.jl for this task (see the docs). So your example might look like this:

using MacroTools: @capture, prewalk

ex = quote
    x = foo(args...)
    y = otherpackage.bar(args...)
end


prewalk(ex) do x
    if @capture(x, f_(args__))
        :(Main.($f)($(args...)))
    else
        x
    end
end

which returns:

quote
    x = Main.(foo)(args...)
    y = Main.(otherpackage.bar)(args...)
end

EDIT: it is probably better to use prewalk here to be able to replace nested function calls as well.

1 Like