# Overload ifthen

**URL:** <https://discourse.julialang.org/t/overload-ifthen/19295>\
**Category:** General Usage\
**Created:** [January 5, 2019, 6:13am UTC](https://discourse.julialang.org/t/overload-ifthen/19295 "2019-01-05T06:13:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Philippe\_Maincon1](https://avatars.discourse-cdn.com/v4/letter/p/ec9cab/32.png) [@Philippe\_Maincon1](https://discourse.julialang.org/u/Philippe_Maincon1)\
**Post date:** [January 5, 2019, 6:13am UTC](https://discourse.julialang.org/t/overload-ifthen/19295/1 "2019-01-05T06:13:02Z")

</div>

In julia 0.7, I had overloaded

```julia
    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

```julia
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?

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [January 5, 2019, 6:15am UTC](https://discourse.julialang.org/t/overload-ifthen/19295/2 "2019-01-05T06:15:59Z")

</div>

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`.

---

<div class="post-metadata">

**Author:** ![Philippe\_Maincon1](https://avatars.discourse-cdn.com/v4/letter/p/ec9cab/32.png) [@Philippe\_Maincon1](https://discourse.julialang.org/u/Philippe_Maincon1)\
**Post date:** [January 5, 2019, 6:19am UTC](https://discourse.julialang.org/t/overload-ifthen/19295/3 "2019-01-05T06:19:27Z")

</div>

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!
