But if I try it, it doesn’t work:
ERROR: syntax: invalid syntax &(Core.tuple(==(1, 2), ==(1, 1)))
 top-level scope at none:0
ERROR: syntax: invalid syntax &(Core.tuple(true, true))
 top-level scope at none:0
I guess I have lost the plot a bit… (I’m used to following ‘what’s on the tin’…)
Yes, that part of the docstring should be fixed (and similarly for
|). But note that the examples there are correct. I made a PR,
If you insist on a prefix syntax, use
(&)(true, true) etc.
Many thanks! Works for me!
You may close this (thanks!)
I could not find an open issue for this (and opening one seemed overkill, compared to just making a PR), so I am not sure what to close here. In any case, this PR should fix the docs.
Great - thanks! [I found out how to mark as ‘solved’]
Also, note that if you find errors like this, it is very easy to make a trivial PR on Github directly, see
This file has been truncated.
# Notes for Julia Contributors
Hi! If you are new to the Julia community: welcome, and thanks for trying Julia. Please be sure to respect our [community standards](https://julialang.org/community/standards) in all interactions.
If you are already familiar with Julia itself, this blog post by Katharine Hyatt on [Making your first Julia pull request](https://kshyatt.github.io/post/firstjuliapr/) is a great way to get started.
## Learning Julia
[The learning page](https://julialang.org/learning) has a great list of resources for new and experienced users alike. [This tutorial video](https://www.youtube.com/watch?v=vWkgEddb4-A) is one recommended starting point, as is the "[Invitation to Julia](https://www.youtube.com/watch?v=gQ1y5NUD_RI)" workshop video from JuliaCon 2015 ([slide materials here](https://github.com/dpsanders/invitation_to_julia)). The [Julia documentation](https://docs.julialang.org) covers the language and core library features, and is searchable.
## Before filing an issue
- Reporting a potential bug? Please read the "[How to file a bug report](https://github.com/JuliaLang/julia/blob/master/CONTRIBUTING.md#how-to-file-a-bug-report)" section to make sure that all necessary information is included.
- Contributing code? Be sure to review the [contributor checklist](https://github.com/JuliaLang/julia/blob/master/CONTRIBUTING.md#contributor-checklist) for helpful tips on the tools we use to build Julia.
- Library feature requests are generally not accepted on this issue tracker. New libraries should be developed as [packages](https://julialang.github.io/Pkg.jl/v1/creating-packages/). Discuss ideas for libraries at the [Julia Discourse forum](https://discourse.julialang.org). Doing so will often lead to pointers to existing projects and bring together collaborators with common interests.
## Contributor Checklist
I did not report it as an error, as there is so much about Julia that I find counter-intuitive that I just assumed it was me…
Interesting: & is bitwise and. && is logical and.
julia> (&)((1 == 2), (1 == 1))
julia> (&&)((1 == 2), (1 == 1))
ERROR: syntax: invalid identifier name "&&"
 top-level scope at REPL:100:
Now I am confused. I thought ‘&’ was the logical AND(?)
Help says && is the ‘short-circuiting’ logical AND(?). What if I just want
the ‘garden-variety’ logical AND?
As the documentation says,
& is the bitwise AND, meaning that it operates bit-to-bit on any pair of integers (plus
missing values) – unlike
&&, which only works on
Bool numbers. For instance:
julia> 0b110 & 0b101
0x04 being the same as binary
But if you use it on
Bool numbers, of course
& will work as a logical AND, without short-circuit.
Yet another difference is that
& is a broadcastable function, so you can use it with arrays, etc. The short-circuit operator only works with a single pair of logical values.
Isn’t it weird that Base.:& is a function, but there is no Base.:&& (the boolean short-circuiting operator)? Is it handled as a keyword?
Short-circuiting means the second part of the statement is guaranteed to only be evaluated if the first one evaluates as true. This is not something that is possible with regular functions and therefore has to be special cased at a compiler level. Because of that,
|| get their own expression types and are not
call expressions, like most infix operators.
Is there a reason why
&(a,b) should be a syntax error when
+(a,b) is allowed?
Otherwise it would seem more logical to make it work as advertised, rather than adjusting the documentation.
& was once used as a unary operator in
ccall and therefore had to be parsed differently. That use was deprecated for Julia 0.7 and according to
https://github.com/JuliaLang/julia/issues/6080#issuecomment-327029743 the plan was to change the parsing for 1.0 but it seems that didn’t happen. I’ve opened an issue to revisit this: https://github.com/JuliaLang/julia/issues/34693.