Hi all,
So using meta-programming, I can define a new function customsum
in a slightly round-about way using interpolation as follows:
fn = :sum
@eval $(Symbol("custom$(fn)"))(x::Vector{<:Number}) = Base.sum(x)
But now, I also want to interpolate onto the RHS of the expression, and include the module name reference (because my actual problem is more complicated than this MWE). I thought the following would work:
@eval $(Symbol("custom$(fn)"))(x::Vector{<:Number}) = $(Symbol("Base.$(fn)"))(x)
but it does not. Calling customsum
results in ERROR: UndefVarError: Base.sum not defined
.
I’ve been banging my head against the wall on this for an hour now trying to work out the right syntax, but am admitting defeat and posting here. Any help would be most greatly appreciated.
Cheers,
Colin