Overload ifthen

In julia 0.7, I had overloaded

    Base.ifelse(cond::𝕓,a::βˆ‚π•£{N},b::𝕣) where{N} = cond ? a        : βˆ‚π•£{N}(b)
    Base.ifelse(cond::𝕓,a::𝕣,b::βˆ‚π•£{N}) where{N} = cond ? βˆ‚π•£{N}(a) : b

essentialy so that

x=cond ? a : b

would promote the output, to get a typestable operation when a and b have different types.

Porting to 1.0, I get LoadError: cannot add methods to a builtin function. In the context of automatic differentiation, this allows me to transparently write typestable code when some variables may be β€œspiced up” as dual/autodiff numbers.

I could write a function ifthen, with the obvious drawback of forcing the evaluation of both a and b. I could write a macro, but then I can no longer write a function ignoring automatic differentiation ('xept for dispatching…) and then use it efficiently with automatic differentiation.

Any ideas?

The old ifelse function already evaluated all of its arguments (it has to, since it’s a function), so I don’t think there’s actually any practical downside to just defining your own ifthen.

1 Like

He he, my mistake. Rereading my code after a long while, I though it was overloading cond ? a : b !!!
Then it’s easy to fix.

Thank you!