# Bitwise and does not parse as function call

**URL:** https://discourse.julialang.org/t/bitwise-and-does-not-parse-as-function-call/1274
**Category:** New to Julia
**Tags:** question
**Created:** [January 4, 2017, 11:08am UTC](https://discourse.julialang.org/t/bitwise-and-does-not-parse-as-function-call/1274 "2017-01-04T11:08:09Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![ethomag](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ethomag/32/421_2.png) [@ethomag](https://discourse.julialang.org/u/ethomag)
#### Post date: [January 4, 2017, 11:08am UTC](https://discourse.julialang.org/t/bitwise-and-does-not-parse-as-function-call/1274/1 "2017-01-04T11:08:10Z")

</div>

This does not seem consistent to me:

```julia

$ ./julia 
               _
   _ _ _(_)_ | A fresh approach to technical computing
  (_) | (_) (_) | Documentation: http://docs.julialang.org
   _ _ _| |_ __ _ | Type "?help" for help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 0.6.0-dev.1889 (2017-01-04 09:08 UTC)
 _/ |\ __'_|_|_|\__'_| | Commit 888f6b5* (0 days old master)
|__/ | x86_64-linux-gnu

julia> 1 & 2
0

julia> &(1, 2)
ERROR: syntax: malformed expression

```

And julia help support this view:

```julia
help?> &
search: &

  &(x, y)

  Bitwise and.
 [...]

```

---

<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 4, 2017, 11:09am UTC](https://discourse.julialang.org/t/bitwise-and-does-not-parse-as-function-call/1274/2 "2017-01-04T11:09:37Z")

</div>

```julia
julia> (&)(1,2)
0

```

---

<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 4, 2017, 4:54pm UTC](https://discourse.julialang.org/t/bitwise-and-does-not-parse-as-function-call/1274/3 "2017-01-04T16:54:06Z")

</div>

It looks like the documentation doesn’t match the behavior. This seems to be a known issue with parsing `&`: [https://github.com/JuliaLang/julia/issues/11521](https://github.com/JuliaLang/julia/issues/11521)

I think the offending line in the documentation is here: (edited, see @tkelman’s post below) [https://github.com/JuliaLang/julia/blob/75cbac32760e90645d579fac877155eb571eee40/base/docs/helpdb/Base.jl#L843](https://github.com/JuliaLang/julia/blob/75cbac32760e90645d579fac877155eb571eee40/base/docs/helpdb/Base.jl#L843)

The best way to get this fixed, if you’re interested in helping, would be to open an issue on github (or, better yet, a pull request with a fix).

---

<div class="post-metadata">

### Author: ![tkelman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkelman/32/692_2.png) [@tkelman](https://discourse.julialang.org/u/tkelman)
#### Post date: [January 4, 2017, 7:41pm UTC](https://discourse.julialang.org/t/bitwise-and-does-not-parse-as-function-call/1274/4 "2017-01-04T19:41:36Z")

</div>

> [@rdeits](#):
>
> I think the offending line in the documentation is here

When you link to lines of code on github, it’s best to hit `y` first. Github will refresh the page but with the current sha of the file you’re looking at inserted into the url. That way even if the file changes on master, like that file just did, the line of code you’re referring to will remain what the link takes you to.

---

<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 4, 2017, 8:11pm UTC](https://discourse.julialang.org/t/bitwise-and-does-not-parse-as-function-call/1274/5 "2017-01-04T20:11:54Z")

</div>

Cool, thanks! Will do. I’ll edit that comment for posterity.

---

<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 5, 2017, 8:56am UTC](https://discourse.julialang.org/t/bitwise-and-does-not-parse-as-function-call/1274/6 "2017-01-05T08:56:10Z")

</div>

> [@rdeits](#):
>
> The best way to get this fixed, if you’re interested in helping, would be to open an issue on github (or, better yet, a pull request with a fix).

Perhaps the docstring could have the infix form `x & y`, and just mention that to refer to the function, use `(&)`.

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [January 5, 2017, 1:13pm UTC](https://discourse.julialang.org/t/bitwise-and-does-not-parse-as-function-call/1274/7 "2017-01-05T13:13:37Z")

</div>

Edit: Removed nonsense

---

<div class="post-metadata">

### Author: ![ethomag](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ethomag/32/421_2.png) [@ethomag](https://discourse.julialang.org/u/ethomag)
#### Post date: [January 5, 2017, 1:34pm UTC](https://discourse.julialang.org/t/bitwise-and-does-not-parse-as-function-call/1274/8 "2017-01-05T13:34:55Z")

</div>

Thanks @rdeits and @Tamas_Papp. I just created the pull request.

While on the subject. It still is not clear to mer why & is different from e.g. |. From the referenced discussion [Cannot define & · Issue #11521 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/11521) it seems like & used to be a unary operator and that legacy is still haunting us ?

Some time ago I attempted to write a macro assembler in julia and needed post increment and decrement of registers. I found then that I could define a function named ++ but not --, which seemed arbitrary. None of those are julian functions and + and - are similar in all relevant aspects, afaik. But (from a fresh julia):

> julia\> ++  
> ERROR: UndefVarError: ++ not defined

> julia\> –  
> ERROR: syntax: invalid operator “–”

---

<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 5, 2017, 1:53pm UTC](https://discourse.julialang.org/t/bitwise-and-does-not-parse-as-function-call/1274/9 "2017-01-05T13:53:54Z")

</div>

AFAIK `&` was part of the [old ccall syntax](http://docs.julialang.org/en/latest/manual/calling-c-and-fortran-code.html#Special-Reference-Syntax-for-ccall-(deprecated):-1).

---

<div class="post-metadata">

### Author: ![ScottPJones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scottpjones/32/146_2.png) [@ScottPJones](https://discourse.julialang.org/u/ScottPJones)
#### Post date: [January 24, 2017, 3:12pm UTC](https://discourse.julialang.org/t/bitwise-and-does-not-parse-as-function-call/1274/10 "2017-01-24T15:12:26Z")

</div>

`++` was added so that people could use it for a generic concatenation operator (or at least for string concatenation) (a la Haskell), to replace the operator punning of the multiplication operator `*` for string concatenation.  
That’s why only `++` is parsed, and not `--`.  
Julia uses `+= 1` and `-= 1` instead of `++` and `--` for pre-increment and pre-decrement.  
Note: for better type-stability, you might be better with something like: `x += one(typeof(x))`  
There’s not really anything for post increment/decrement though AFAIK.
