Skip to content

Commit

Permalink
Add .& and .|
Browse files Browse the repository at this point in the history
These replace element-wise & and |, which are deprecated in Julia 0.6.
This syntax is not supported by Julia 0.4.
  • Loading branch information
nalimilan committed Jan 14, 2017
1 parent 9e518ff commit d2b16ae
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ Currently, the `@compat` macro supports the following syntaxes:

* The method of `!` to negate functions (typically used as a unary operator, as in `!isinteger`) can be used in 0.5 and earlier. [#17155](https://github.com/JuliaLang/julia/pull/17155)

* `.&` and `.|` are short syntax for `broadcast(&, xs...)` and `broadcast(|, xs...)` (respectively) in Julia 0.6 (only supported on Julia 0.5 and above) [#17623](https://github.com/JuliaLang/julia/pull/17623)

## Renamed functions

* `pointer_to_array` and `pointer_to_string` have been replaced with `unsafe_wrap(Array, ...)` and `unsafe_wrap(String, ...)` respectively
Expand Down
7 changes: 7 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1759,4 +1759,11 @@ if VERSION < v"0.5.0-dev+3669"
scale!(similar(A, promote_op(*, eltype(A), eltype(D.diag))), D.diag, A)
end

if VERSION >= v"0.5.0" && VERSION < v"0.6.0-dev.1614"
# To work around unsupported syntax on Julia 0.4
include_string("export .&, .|")
include_string(".&(xs...) = broadcast(&, xs...)")
include_string(".|(xs...) = broadcast(|, xs...)")
end

end # module
6 changes: 6 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1577,3 +1577,9 @@ D = Diagonal(x)
A = view(rand(5,5), 1:3, 1:3)
@test D*A == Diagonal(copy(x)) * copy(A)
@test A*D == copy(A) * Diagonal(copy(x))

# julia#17623
@static if VERSION >= v"0.5.0" # To work around unsupported syntax on Julia 0.4
@test [true, false] .& [true, true] == [true, false]
@test [true, false] .| [true, true] == [true, true]
end

0 comments on commit d2b16ae

Please sign in to comment.