There’s no need to write a macro for this.
function sumAbs(model, expr::Vector)
slack = @variable(model, [1:length(expr)], lower_bound = 0.0)
@constraint(model, slack .>= expr)
@constraint(model, slack .>= -expr)
return @expression(model, sum(slack))
end
model = Model()
@variable(model, x[1:3])
@variable(model, y[1:3])
ex = @expression(model, [a = 1:3], x[a] - y[a])
z = sumAbs(model, ex)
In general, you should almost never need to write a macro. They are difficult to write, and functions have the benefit of having typed arguments.