From 4793e88185573387a514e3e40ca14128d4920886 Mon Sep 17 00:00:00 2001 From: Katharine Hyatt Date: Sat, 24 Dec 2016 23:38:16 -0800 Subject: [PATCH] Add doctest example for fill! (#19422) * Add doctest example for fill! * Add more doctests --- base/docs/helpdb/Base.jl | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/base/docs/helpdb/Base.jl b/base/docs/helpdb/Base.jl index 0e4bfb83edb5d..b8667fcf12711 100644 --- a/base/docs/helpdb/Base.jl +++ b/base/docs/helpdb/Base.jl @@ -15,6 +15,29 @@ systemerror Fill array `A` with the value `x`. If `x` is an object reference, all elements will refer to the same object. `fill!(A, Foo())` will return `A` filled with the result of evaluating `Foo()` once. + +```jldoctest +julia> A = zeros(2,3) +2×3 Array{Float64,2}: + 0.0 0.0 0.0 + 0.0 0.0 0.0 + +julia> fill!(A, 2.) +2×3 Array{Float64,2}: + 2.0 2.0 2.0 + 2.0 2.0 2.0 + +julia> a = [1, 1, 1]; A = fill!(Vector{Vector{Int}}(3), a); a[1] = 2; A +3-element Array{Array{Int64,1},1}: + [2,1,1] + [2,1,1] + [2,1,1] + +julia> x = 0; f() = (global x += 1; x); fill!(Vector{Int}(3), f()) + 1 + 1 + 1 +``` """ fill!