Skip to content

Commit 7e570d4

Browse files
committed
Move docs inline from helpdb/Base.jl
1 parent 4793e88 commit 7e570d4

18 files changed

+545
-590
lines changed

base/abstractarray.jl

+30
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/bitarray.jl

+17
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

+17
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

base/complex.jl

+13
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,19 @@ real(T::Type) = typeof(real(zero(T)))
7575
real{T<:Real}(::Type{T}) = T
7676
real{T<:Real}(::Type{Complex{T}}) = T
7777

78+
"""
79+
isreal(x) -> Bool
80+
81+
Test whether `x` or all its elements are numerically equal to some real number.
82+
83+
```jldoctest
84+
julia> isreal(5.)
85+
true
86+
87+
julia> isreal([4.; complex(0,1)])
88+
false
89+
```
90+
"""
7891
isreal(x::Real) = true
7992
isreal(z::Complex) = iszero(imag(z))
8093
"""

base/dict.jl

+17
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,23 @@ function sizehint!(d::Dict, newsz)
283283
rehash!(d, newsz)
284284
end
285285

286+
"""
287+
empty!(collection) -> collection
288+
289+
Remove all elements from a `collection`.
290+
291+
```jldoctest
292+
julia> A = Dict("a" => 1, "b" => 2)
293+
Dict{String,Int64} with 2 entries:
294+
"b" => 2
295+
"a" => 1
296+
297+
julia> empty!(A);
298+
299+
julia> A
300+
Dict{String,Int64} with 0 entries
301+
```
302+
"""
286303
function empty!{K,V}(h::Dict{K,V})
287304
fill!(h.slots, 0x0)
288305
sz = length(h.slots)

0 commit comments

Comments
 (0)