# Operator overloading of &&

**URL:** <https://discourse.julialang.org/t/operator-overloading-of/73735>\
**Category:** General Usage\
**Created:** [December 28, 2021, 11:02pm UTC](https://discourse.julialang.org/t/operator-overloading-of/73735 "2021-12-28T23:02:15Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![atteson](https://avatars.discourse-cdn.com/v4/letter/a/91b2a8/32.png) [@atteson](https://discourse.julialang.org/u/atteson)\
**Post date:** [December 28, 2021, 11:02pm UTC](https://discourse.julialang.org/t/operator-overloading-of/73735/1 "2021-12-28T23:02:15Z")

</div>

As far as I can tell, there is no ability to overload &&. It doesn’t seem to be a function defined in Base as other operators are. I assume this is because it doesn’t behave the way other functions do in that it short circuits (the 2nd argument is lazily evaluated). Is there any way around this?

---

<div class="post-metadata">

**Author:** ![Bardo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bardo/32/21601_2.png) [@Bardo](https://discourse.julialang.org/u/Bardo)\
**Post date:** [December 28, 2021, 11:32pm UTC](https://discourse.julialang.org/t/operator-overloading-of/73735/2 "2021-12-28T23:32:43Z")

</div>

Found the unusual position of the point by chance:

```julia
julia> [true, false] .&& false
2-element BitVector:
 0
 0

```

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [December 28, 2021, 11:35pm UTC](https://discourse.julialang.org/t/operator-overloading-of/73735/3 "2021-12-28T23:35:16Z")

</div>

No, you can’t overload `&&`.

---

<div class="post-metadata">

**Author:** ![Bardo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bardo/32/21601_2.png) [@Bardo](https://discourse.julialang.org/u/Bardo)\
**Post date:** [December 28, 2021, 11:41pm UTC](https://discourse.julialang.org/t/operator-overloading-of/73735/4 "2021-12-28T23:41:20Z")

</div>

Hm, I can’t tell for the overloading.  
What is then `&&.` ?  
It throws an error in the example above.

---

<div class="post-metadata">

**Author:** ![ToucheSir](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/touchesir/32/14411_2.png) [@ToucheSir](https://discourse.julialang.org/u/ToucheSir)\
**Post date:** [December 29, 2021, 12:07am UTC](https://discourse.julialang.org/t/operator-overloading-of/73735/5 "2021-12-29T00:07:08Z")

</div>

```julia-repl
julia> Meta.@lower true && false
:($(Expr(:thunk, CodeInfo(
    @ none within `top-level scope`
1 ─ goto #3 if not true
2 ─ return false
3 ─ return false
))))

julia> Meta.@lower true .&& false
:($(Expr(:thunk, CodeInfo(
    @ none within `top-level scope`
1 ─ %1 = Base.broadcasted(Base.andand, true, false)
│ %2 = Base.materialize(%1)
└── return %2
))))

```

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [December 29, 2021, 3:24am UTC](https://discourse.julialang.org/t/operator-overloading-of/73735/6 "2021-12-29T03:24:29Z")

</div>

No, the `.` above was just finishing the sentence. `&&.` doesn’t have a meaning in Julia. Like other binary operators, the `.` goes first: `.+` `.*` `.&&`

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [December 29, 2021, 10:32am UTC](https://discourse.julialang.org/t/operator-overloading-of/73735/7 "2021-12-29T10:32:18Z")

</div>

> [@atteson](#):
>
> As far as I can tell, there is no ability to overload &&. It doesn’t seem to be a function defined in Base as other operators are.

No, it’s not a function at all but rather a control flow syntax similar to `if` or `? :`.

> [@atteson](#):
>
> Is there any way around this?

Depends on what you are trying to accomplish. If you are willing to involve macros you have great possibilities to customize the meaning of anything that is syntactically valid.
