Help with adding dots to functions in an expression

Hi,

I am trying to distribute dots wherever necessary, so that I can apply an expression to a dataframe and evaluate it.

say I give it the expression:

My_Expression = :(3 + log(x1) + 2 * sqrt(abs(log(x2))) + asin(x4))

and I want it to return:

Returned_Expression = :(3 + log.(x1) + 2 * sqrt.(abs.(log.(x2))) + asin.(x4))

I have this code that works in version 0.6.3, where it successfully adds dots to every function call inside the expression, but when I tried to run it on version 0.7 it interpolates the expression with a dollar sign.

function add_dots(x::Expr)
    for argument in x.args
        if argument isa Expr
            if argument.args[1] != :*
                argument.head = :.
            end
        add_dots(argument)
        end
    end
    return x
end

Any thoughts on why this may be happening or what to do about it would be much appreciated!

-Sarah

Have you seen the @. macro?

5 Likes