Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move docs inline from helpdb/Base.jl #19674

Merged
merged 1 commit into from
Jan 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,41 @@ _length(A) = length(A)
endof(a::AbstractArray) = length(a)
first(a::AbstractArray) = a[first(eachindex(a))]

"""
first(coll)

Get the first element of an iterable collection. Returns the start point of a
`Range` even if it is empty.

```jldoctest
julia> first(2:2:10)
2

julia> first([1; 2; 3; 4])
1
```
"""
function first(itr)
state = start(itr)
done(itr, state) && throw(ArgumentError("collection must be non-empty"))
next(itr, state)[1]
end

"""
last(coll)

Get the last element of an ordered collection, if it can be computed in O(1) time. This is
accomplished by calling [`endof`](@ref) to get the last index. Returns the end
point of a `Range` even if it is empty.

```jldoctest
julia> last(1:2:10)
9

julia> last([1; 2; 3; 4])
4
```
"""
last(a) = a[end]

"""
Expand Down
35 changes: 35 additions & 0 deletions base/bool.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@ typemax(::Type{Bool}) = true

## boolean operations ##

"""
!(x)

Boolean not.

```jldoctest
julia> !true
false

julia> !false
true

julia> ![true false true]
1×3 Array{Bool,2}:
false true false
```
"""
function !(x::Bool)
## We need a better heuristic to detect this automatically
@_pure_meta
Expand All @@ -23,6 +40,24 @@ end
(~)(x::Bool) = !x
(&)(x::Bool, y::Bool) = box(Bool,and_int(unbox(Bool,x),unbox(Bool,y)))
(|)(x::Bool, y::Bool) = box(Bool,or_int(unbox(Bool,x),unbox(Bool,y)))

"""
xor(x, y)
⊻(x, y)

Bitwise exclusive or of `x` and `y`. The infix operation
`a ⊻ b` is a synonym for `xor(a,b)`, and
`⊻` can be typed by tab-completing `\\xor`
or `\\veebar` in the Julia REPL.

```jldoctest
julia> [true; true; false] ⊻ [true; false; false]
3-element Array{Bool,1}:
false
true
false
```
"""
xor(x::Bool, y::Bool) = (x!=y)

>>(x::Bool, c::Unsigned) = Int(x) >> c
Expand Down
13 changes: 13 additions & 0 deletions base/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@ real(T::Type) = typeof(real(zero(T)))
real{T<:Real}(::Type{T}) = T
real{T<:Real}(::Type{Complex{T}}) = T

"""
isreal(x) -> Bool
Test whether `x` or all its elements are numerically equal to some real number.
```jldoctest
julia> isreal(5.)
true
julia> isreal([4.; complex(0,1)])
false
```
"""
isreal(x::Real) = true
isreal(z::Complex) = iszero(imag(z))
"""
Expand Down
17 changes: 17 additions & 0 deletions base/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,23 @@ function sizehint!(d::Dict, newsz)
rehash!(d, newsz)
end

"""
empty!(collection) -> collection

Remove all elements from a `collection`.

```jldoctest
julia> A = Dict("a" => 1, "b" => 2)
Dict{String,Int64} with 2 entries:
"b" => 2
"a" => 1

julia> empty!(A);

julia> A
Dict{String,Int64} with 0 entries
```
"""
function empty!{K,V}(h::Dict{K,V})
fill!(h.slots, 0x0)
sz = length(h.slots)
Expand Down
Loading