Skip to content

Commit 69c7554

Browse files
committed
Move docs inline from helpdb/Base.jl
1 parent 5989eaf commit 69c7554

16 files changed

+575
-655
lines changed

base/abstractarray.jl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,41 @@ _length(A) = length(A)
127127
endof(a::AbstractArray) = length(a)
128128
first(a::AbstractArray) = a[first(eachindex(a))]
129129

130+
"""
131+
first(coll)
132+
133+
Get the first element of an iterable collection. Returns the start point of a
134+
`Range` even if it is empty.
135+
136+
```jldoctest
137+
julia> first(2:2:10)
138+
2
139+
140+
julia> first([1; 2; 3; 4])
141+
1
142+
```
143+
"""
130144
function first(itr)
131145
state = start(itr)
132146
done(itr, state) && throw(ArgumentError("collection must be non-empty"))
133147
next(itr, state)[1]
134148
end
149+
150+
"""
151+
last(coll)
152+
153+
Get the last element of an ordered collection, if it can be computed in O(1) time. This is
154+
accomplished by calling [`endof`](@ref) to get the last index. Returns the end
155+
point of a `Range` even if it is empty.
156+
157+
```jldoctest
158+
julia> last(1:2:10)
159+
9
160+
161+
julia> last([1; 2; 3; 4])
162+
4
163+
```
164+
"""
135165
last(a) = a[end]
136166

137167
"""

base/array.jl

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,13 @@ function getindex(::Type{Any}, vals::ANY...)
169169
end
170170
getindex(::Type{Any}) = Array{Any,1}(0)
171171

172+
"""
173+
fill!(A, x)
174+
175+
Fill array `A` with the value `x`. If `x` is an object reference, all elements will refer to
176+
the same object. `fill!(A, Foo())` will return `A` filled with the result of evaluating
177+
`Foo()` once.
178+
"""
172179
function fill!(a::Union{Array{UInt8}, Array{Int8}}, x::Integer)
173180
ccall(:memset, Ptr{Void}, (Ptr{Void}, Cint, Csize_t), a, x, length(a))
174181
return a
@@ -205,6 +212,73 @@ dims)` will return an array filled with the result of evaluating `Foo()` once.
205212
fill(v, dims::Dims) = fill!(Array{typeof(v)}(dims), v)
206213
fill(v, dims::Integer...) = fill!(Array{typeof(v)}(dims...), v)
207214

215+
"""
216+
zeros(type, dims)
217+
218+
Create an array of all zeros of specified type.
219+
The type defaults to `Float64` if not specified.
220+
221+
```jldoctest
222+
julia> zeros(Int8, 2, 3)
223+
2×3 Array{Int8,2}:
224+
0 0 0
225+
0 0 0
226+
```
227+
"""
228+
zeros
229+
230+
"""
231+
zeros(A)
232+
233+
Create an array of all zeros with the same element type and shape as `A`.
234+
235+
```jldoctest
236+
julia> A = [1 2; 3 4]
237+
2×2 Array{Int64,2}:
238+
1 2
239+
3 4
240+
241+
julia> zeros(A)
242+
2×2 Array{Int64,2}:
243+
0 0
244+
0 0
245+
```
246+
"""
247+
zeros
248+
249+
"""
250+
ones(type, dims)
251+
252+
Create an array of all ones of specified type. The type defaults to `Float64` if not specified.
253+
254+
```jldoctest
255+
julia> ones(Complex128, 2, 3)
256+
2×3 Array{Complex{Float64},2}:
257+
1.0+0.0im 1.0+0.0im 1.0+0.0im
258+
1.0+0.0im 1.0+0.0im 1.0+0.0im
259+
```
260+
"""
261+
ones
262+
263+
"""
264+
ones(A)
265+
266+
Create an array of all ones with the same element type and shape as `A`.
267+
268+
```jldoctest
269+
julia> A = [1 2; 3 4]
270+
2×2 Array{Int64,2}:
271+
1 2
272+
3 4
273+
274+
julia> ones(A)
275+
2×2 Array{Int64,2}:
276+
1 1
277+
1 1
278+
```
279+
"""
280+
ones
281+
208282
for (fname, felt) in ((:zeros,:zero), (:ones,:one))
209283
@eval begin
210284
($fname)(T::Type, dims...) = fill!(Array{T}(dims...), ($felt)(T))

base/bitarray.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,6 +1301,23 @@ function (|)(B::BitArray, x::Bool)
13011301
end
13021302
(|)(x::Bool, B::BitArray) = B | x
13031303

1304+
"""
1305+
xor(x, y)
1306+
⊻(x, y)
1307+
1308+
Bitwise exclusive or of `x` and `y`. The infix operation
1309+
`a ⊻ b` is a synonym for `xor(a,b)`, and
1310+
`⊻` can be typed by tab-completing `\\xor`
1311+
or `\\veebar` in the Julia REPL.
1312+
1313+
```jldoctest
1314+
julia> [true; true; false] ⊻ [true; false; false]
1315+
3-element Array{Bool,1}:
1316+
false
1317+
true
1318+
false
1319+
```
1320+
"""
13041321
function xor(B::BitArray, x::Bool)
13051322
x ? ~B : copy(B)
13061323
end

base/bool.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,23 @@ typemax(::Type{Bool}) = true
1414

1515
## boolean operations ##
1616

17+
"""
18+
!(x)
19+
20+
Boolean not.
21+
22+
```jldoctest
23+
julia> !true
24+
false
25+
26+
julia> !false
27+
true
28+
29+
julia> ![true false true]
30+
1×3 Array{Bool,2}:
31+
false true false
32+
```
33+
"""
1734
function !(x::Bool)
1835
## We need a better heuristic to detect this automatically
1936
@_pure_meta

0 commit comments

Comments
 (0)