# Counter-intuitive behaviour of the & function. Is it working as intended?

**URL:** <https://discourse.julialang.org/t/counter-intuitive-behaviour-of-the-function-is-it-working-as-intended/54246>\
**Category:** General Usage\
**Tags:** question\
**Created:** [January 30, 2021, 2:48am UTC](https://discourse.julialang.org/t/counter-intuitive-behaviour-of-the-function-is-it-working-as-intended/54246 "2021-01-30T02:48:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![CaFe](https://avatars.discourse-cdn.com/v4/letter/c/ce73a5/32.png) [@CaFe](https://discourse.julialang.org/u/CaFe)\
**Post date:** [January 30, 2021, 2:48am UTC](https://discourse.julialang.org/t/counter-intuitive-behaviour-of-the-function-is-it-working-as-intended/54246/1 "2021-01-30T02:48:31Z")

</div>

Hello Everyone,  
I am a beginner to Julia and found the following behaviour of the & bitwise and operator rather perplexing.

When I type in the REPL something like:

julia\> 1 & 3

Everything goes ok and I get an answer:

1

However, when I type:

julia\> &(1, 3)

I get the following error:

ERROR: syntax: invalid syntax &(1, 3) around REPL[3]:1  
Stacktrace:  
[1] top-level scope at REPL[3]:1

I found this very counter-intuitive, since this syntax is perfectly valid for an operator like +.  
So I decide to write the following:

julia\> methods(&)

And I get:

# 16 methods for generic function “&”:

[1] &(a::BigInt, b::BigInt, c::BigInt, d::BigInt, e::BigInt) in Base.GMP at gmp.jl:518  
[2] &(a::BigInt, b::BigInt, c::BigInt, d::BigInt) in Base.GMP at gmp.jl:517  
[3] &(a::BigInt, b::BigInt, c::BigInt) in Base.GMP at gmp.jl:516  
[4] &(x::BigInt, y::BigInt) in Base.GMP at gmp.jl:476  
[5] &(a::Missing, b::Bool) in Base at missing.jl:159  
[6] &(::Missing, ::Missing) in Base at missing.jl:158  
[7] &(::Missing, ::Integer) in Base at missing.jl:161  
[8] &(b::Bool, a::Missing) in Base at missing.jl:160  
[9] &(x::Bool, y::Bool) in Base at bool.jl:40  
[10] &(x::T, y::T) where T\<:Union{Int128, Int16, Int32, Int64, Int8, UInt128, UInt16, UInt32, UInt64, UInt8} in Base at int.jl:308  
[11] &(x::Integer) in Base at operators.jl:515  
[12] &(x::T, y::T) where T\<:Integer in Base at promotion.jl:394  
[13] &(a::Integer, b::Integer) in Base at int.jl:918  
[14] &(::Integer, ::Missing) in Base at missing.jl:162  
[15] &(left::Base.AbstractCmd, right::Base.AbstractCmd) in Base at cmd.jl:245  
[16] &(a, b, c, xs…) in Base at operators.jl:538

I found this really intriguing, since according to this message &(x, y) should be defined for integers. The same does not happen for the other bitwise operators | and \veebar. In those cases I do not get an error.

What is wrong? Is it some bug, is it an intended behaviour, or am I misunderstanding something?

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [January 30, 2021, 2:52am UTC](https://discourse.julialang.org/t/counter-intuitive-behaviour-of-the-function-is-it-working-as-intended/54246/2 "2021-01-30T02:52:41Z")

</div>

`(&)(1,3)` works. I think this is just a parsing thing.

---

<div class="post-metadata">

**Author:** ![CaFe](https://avatars.discourse-cdn.com/v4/letter/c/ce73a5/32.png) [@CaFe](https://discourse.julialang.org/u/CaFe)\
**Post date:** [January 30, 2021, 2:59am UTC](https://discourse.julialang.org/t/counter-intuitive-behaviour-of-the-function-is-it-working-as-intended/54246/4 "2021-01-30T02:59:26Z")

</div>

Thank you, that helps.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [January 30, 2021, 3:31pm UTC](https://discourse.julialang.org/t/counter-intuitive-behaviour-of-the-function-is-it-working-as-intended/54246/5 "2021-01-30T15:31:00Z")

</div>

Also, its docstring (`?&`) mentions that one needs to

> Add parentheses for function application form: `(&)(x, y)`.

---

<div class="post-metadata">

**Author:** ![CaFe](https://avatars.discourse-cdn.com/v4/letter/c/ce73a5/32.png) [@CaFe](https://discourse.julialang.org/u/CaFe)\
**Post date:** [January 30, 2021, 3:35pm UTC](https://discourse.julialang.org/t/counter-intuitive-behaviour-of-the-function-is-it-working-as-intended/54246/6 "2021-01-30T15:35:36Z")

</div>

So it’s intentional and documented. That solves my question.
