but I would be careful about redefining how basic functionality like this works, at a minimum it makes it harder for others to understand your code. Choosing your own alternative Unicode identifier as you do above is preferable in my opinion, in these situations where I modify a defined infix operator I often add suffixes to indicate what the modification is doing, e.g. in this case maybe ≈₀₁
function _approx!(ex::Expr, kwargs)
_approx!.(ex.args, Ref(kwargs))
if ex.head == :call && ex.args[1] == :≈
append!(ex.args, kwargs)
end
end
_approx!(x, kwargs) = nothing
macro approx(args...)
kwargs = [Expr(:kw, arg.args...) for arg in args[1:end-1]]
ex = args[end]
_approx!(ex, kwargs)
return ex
end
You can always just redefine ≈ within your module:
≈(x,y) = isapprox(x,y,atol=0.01)
This doesn’t affect Base.≈ and is not type-piracy… it is defining a new module-local function of the same name. Of course, this could be confusing for someone reading your code, so it might be clearer to give it a different name like ≈₂ (which is a valid operator name in Julia).
But if you just want to change the tolerance in some @test calls, you can also use @test x ≈ y atol=0.01 to pass keyword arguments to ≈.