diff --git a/base/refpointer.jl b/base/refpointer.jl index 416a748261414..88e59ae6a3cc5 100644 --- a/base/refpointer.jl +++ b/base/refpointer.jl @@ -20,8 +20,8 @@ There is no invalid (NULL) `Ref` in Julia, but a `C_NULL` instance of `Ptr` can a `ccall` Ref argument. # Use in broadcasting +`Ref` is sometimes used in broadcasting in order to treat the referenced values as a scalar: -Broadcasting with `Ref(x)` treats `x` as a scalar: ```jldoctest julia> isa.(Ref([1,2,3]), [Array, Dict, Int]) 3-element BitArray{1}: diff --git a/doc/src/manual/arrays.md b/doc/src/manual/arrays.md index 1032112e63d7c..4a40d616242d8 100644 --- a/doc/src/manual/arrays.md +++ b/doc/src/manual/arrays.md @@ -933,7 +933,7 @@ julia> convert.(Float32, [1, 2]) 1.0 2.0 -julia> ceil.((UInt8,), [1.2 3.4; 5.6 6.7]) +julia> ceil.(UInt8, [1.2 3.4; 5.6 6.7]) 2×2 Array{UInt8,2}: 0x02 0x04 0x06 0x07 @@ -945,6 +945,17 @@ julia> string.(1:3, ". ", ["First", "Second", "Third"]) "3. Third" ``` +Sometimes, you want a container (like an array) that would normally participate in broadcast to be "protected" +from broadcast's behavior of iterating over all of its elements. By placing it inside another container +(like a single element [`Tuple`](@ref)) broadcast will treat it as a single value. +```jldoctest +julia> ([1, 2, 3], [4, 5, 6]) .+ ([1, 2, 3],) +([2, 4, 6], [5, 7, 9]) + +julia> ([1, 2, 3], [4, 5, 6]) .+ tuple([1, 2, 3]) +([2, 4, 6], [5, 7, 9]) +``` + ## Implementation The base array type in Julia is the abstract type [`AbstractArray{T,N}`](@ref). It is parameterized by