Skip to content

Commit

Permalink
document some undocumented exports (JuliaLang#27107)
Browse files Browse the repository at this point in the history
∋, ∉, ∌, VecOrMat{T}, @v_str, VersionNumber, Base,
Base.Broadcast, Base.GC, Inf/Inf64, NaN/NaN64
AbstractVecOrMat{T}, issubset/⊆/⊇, ⊊/⊋, ⊈/⊉, issetequal
  • Loading branch information
fredrikekre committed May 16, 2018
1 parent 11c803c commit 6291d3e
Show file tree
Hide file tree
Showing 13 changed files with 173 additions and 53 deletions.
78 changes: 56 additions & 22 deletions base/abstractset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -198,23 +198,6 @@ end
<( l::AbstractSet, r::AbstractSet) = l r
<=(l::AbstractSet, r::AbstractSet) = l r

"""
issubset(a, b)
⊆(a,b) -> Bool
⊈(a,b) -> Bool
⊊(a,b) -> Bool
Determine whether every element of `a` is also in `b`, using [`in`](@ref).
# Examples
```jldoctest
julia> issubset([1, 2], [1, 2, 3])
true
julia> issubset([1, 2, 3], [1, 2])
false
```
"""
function issubset(l, r)

rlen = length(r)
Expand All @@ -233,10 +216,30 @@ function issubset(l, r)
end
return true
end
# use the implementation below when it becoms as efficient
# use the implementation below when it becomes as efficient
# issubset(l, r) = all(_in(r), l)

const = issubset
(l, r) = r l
"""
issubset(a, b)
⊆(a,b) -> Bool
⊇(b, a) -> Bool
Determine whether every element of `a` is also in `b`, using [`in`](@ref).
# Examples
```jldoctest
julia> issubset([1, 2], [1, 2, 3])
true
julia> [1, 2, 3] ⊆ [1, 2]
false
julia> [1, 2, 3] ⊇ [1, 2]
true
```
"""
issubset, ,

"""
issetequal(a, b)
Expand All @@ -257,11 +260,42 @@ issetequal(l, r) = length(l) == length(r) && l ⊆ r
issetequal(l::AbstractSet, r::AbstractSet) = l == r

(l, r) = length(l) < length(r) && l r
(l, r) = !(l, r)
(l, r) = r l
"""
⊊(a, b)
⊋(b, a)
(l, r) = r l
Determines if `a` is a subset of, but not equal to, `b`.
# Examples
```jldoctest
julia> (1, 2) ⊊ (1, 2, 3)
true
julia> (1, 2) ⊊ (1, 2)
false
```
"""
,

(l, r) = !(l, r)
(l, r) = r l
(l, r) = r l
"""
⊈(a, b)
⊉(b, a)
Negation of `⊆` and `⊇`, i.e. checks that `a` is not a subset of `b`.
# Examples
```jldoctest
julia> (1, 2) ⊈ (2, 3)
true
julia> (1, 2) ⊈ (1, 2, 3)
false
```
"""
,

filter(pred, s::AbstractSet) = mapfilter(pred, push!, s, emptymutable(s))

Expand Down
11 changes: 11 additions & 0 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ Supertype for two-dimensional arrays (or array-like types) with
elements of type `T`. Alias for [`AbstractArray{T,2}`](@ref).
"""
const AbstractMatrix{T} = AbstractArray{T,2}

"""
AbstractVecOrMat{T}
Union type of [`AbstractVector{T}`](@ref) and [`AbstractMatrix{T}`](@ref).
"""
const AbstractVecOrMat{T} = Union{AbstractVector{T}, AbstractMatrix{T}}
const RangeIndex = Union{Int, AbstractRange{Int}, AbstractUnitRange{Int}}
const DimOrInd = Union{Integer, AbstractUnitRange}
Expand Down Expand Up @@ -58,6 +64,11 @@ Two-dimensional dense array with elements of type `T`, often used to represent
a mathematical matrix. Alias for [`Array{T,2}`](@ref).
"""
const Matrix{T} = Array{T,2}
"""
VecOrMat{T}
Union type of [`Vector{T}`](@ref) and [`Matrix{T}`](@ref).
"""
const VecOrMat{T} = Union{Vector{T}, Matrix{T}}

const DenseVector{T} = DenseArray{T,1}
Expand Down
5 changes: 5 additions & 0 deletions base/broadcast.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

"""
Base.Broadcast
Module containing the broadcasting implementation.
"""
module Broadcast

using .Base.Cartesian
Expand Down
11 changes: 7 additions & 4 deletions base/float.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,21 @@ const NaN32 = bitcast(Float32, 0x7fc00000)
const Inf64 = bitcast(Float64, 0x7ff0000000000000)
const NaN64 = bitcast(Float64, 0x7ff8000000000000)

const Inf = Inf64
"""
Inf
Inf, Inf64
Positive infinity of type [`Float64`](@ref).
"""
const Inf = Inf64
Inf, Inf64

const NaN = NaN64
"""
NaN
NaN, NaN64
A not-a-number value of type [`Float64`](@ref).
"""
const NaN = NaN64
NaN, NaN64

## conversions to floating-point ##
Float16(x::Integer) = convert(Float16, convert(Float32, x))
Expand Down
5 changes: 5 additions & 0 deletions base/gcutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ Immediately run finalizers registered for object `x`.
finalize(@nospecialize(o)) = ccall(:jl_finalize_th, Cvoid, (Ptr{Cvoid}, Any,),
Core.getptls(), o)

"""
Base.GC
Module with garbage collection utilities.
"""
module GC

"""
Expand Down
30 changes: 16 additions & 14 deletions base/pair.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

struct Pair{A, B}
first::A
second::B
function Pair{A, B}(@nospecialize(a), @nospecialize(b)) where {A, B}
@_inline_meta
# if we didn't inline this, it's probably because the callsite was actually dynamic
# to avoid potentially compiling many copies of this, we mark the arguments with `@nospecialize`
# but also mark the whole function with `@inline` to ensure we will inline it whenever possible
# (even if `convert(::Type{A}, a::A)` for some reason was expensive)
return new(a, b)
end
end
Pair(a::A, b::B) where {A, B} = Pair{A, B}(a, b)
const => = Pair

"""
Pair(x, y)
x => y
Expand Down Expand Up @@ -28,20 +43,7 @@ foo
7
```
"""
struct Pair{A, B}
first::A
second::B
function Pair{A, B}(@nospecialize(a), @nospecialize(b)) where {A, B}
@_inline_meta
# if we didn't inline this, it's probably because the callsite was actually dynamic
# to avoid potentially compiling many copies of this, we mark the arguments with `@nospecialize`
# but also mark the whole function with `@inline` to ensure we will inline it whenever possible
# (even if `convert(::Type{A}, a::A)` for some reason was expensive)
return new(a, b)
end
end
Pair(a::A, b::B) where {A, B} = Pair{A, B}(a, b)
const => = Pair
Pair, =>

start(p::Pair) = 1
done(p::Pair, i) = i>2
Expand Down
33 changes: 23 additions & 10 deletions base/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -734,13 +734,16 @@ end


## in & contains
in(x, itr) = any(y -> y == x, itr)
const = in
(itr, x) = (x, itr)
(x, itr) = !(x, itr)
(itr, x) = !(itr, x)

"""
in(item, collection) -> Bool
∈(item,collection) -> Bool
∋(collection,item) -> Bool
∉(item,collection) -> Bool
∌(collection,item) -> Bool
∈(item, collection) -> Bool
∋(collection, item) -> Bool
Determine whether an item is in the given collection, in the sense that it is
[`==`](@ref) to one of the values generated by iterating over the collection.
Expand Down Expand Up @@ -779,16 +782,26 @@ julia> missing in Set([1, 2])
false
```
"""
in(x, itr) = any(y -> y == x, itr)
in,

const = in
(x, itr)=!(x, itr)
(itr, x)= (x, itr)
(itr, x)=!(itr, x)
"""
∉(item, collection) -> Bool
∌(collection, item) -> Bool
Negation of `∈` and `∋`, i.e. checks that `item` is not in `collection`.
## count
# Examples
```jldoctest
julia> 1 ∉ 2:4
true
julia> 1 ∉ 1:3
false
```
"""
,

## count
"""
count(p, itr) -> Integer
count(itr) -> Integer
Expand Down
30 changes: 30 additions & 0 deletions base/version.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,23 @@
## semantic version numbers (http:https://semver.org)

const VInt = UInt32
"""
VersionNumber
Version number type which follow the specifications of
[semantic versioning](http:https://semver.org), composed of major, minor
and patch numeric values, followed by pre-release and build
alpha-numeric annotations. See also [`@v_str`](@ref).
# Examples
```jldoctest
julia> VersionNumber("1.2.3")
v"1.2.3"
julia> VersionNumber("2.0.1-rc1")
v"2.0.1-rc1"
```
"""
struct VersionNumber
major::VInt
minor::VInt
Expand Down Expand Up @@ -105,6 +121,20 @@ function VersionNumber(v::AbstractString)
return VersionNumber(major, minor, patch, prerl, build)
end

"""
@v_str
String macro used to parse a string to a [`VersionNumber`](@ref).
# Examples
```jldoctest
julia> v"1.2.3"
v"1.2.3"
julia> v"2.0.1-rc1"
v"2.0.1-rc1"
```
"""
macro v_str(v); VersionNumber(v); end

typemin(::Type{VersionNumber}) = v"0-"
Expand Down
2 changes: 2 additions & 0 deletions doc/src/base/arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Core.AbstractArray
Base.AbstractVector
Base.AbstractMatrix
Base.AbstractVecOrMat
Core.Array
Core.Array(::UndefInitializer, ::Any)
Core.Array(::Nothing, ::Any)
Expand All @@ -20,6 +21,7 @@ Base.Matrix
Base.Matrix(::UndefInitializer, ::Any, ::Any)
Base.Matrix(::Nothing, ::Any, ::Any)
Base.Matrix(::Missing, ::Any, ::Any)
Base.VecOrMat
Base.getindex(::Type, ::Any...)
Base.zeros
Base.ones
Expand Down
10 changes: 10 additions & 0 deletions doc/src/base/base.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,16 @@ primitive type

## Base Modules
```@docs
Base.Base
Base.Broadcast
Base.Docs
Base.Iterators
Base.Libc
Base.Meta
Base.StackTraces
Base.Sys
Base.Threads
Base.GC
```

## All Objects
Expand Down Expand Up @@ -264,6 +267,13 @@ Base.Sys.windows_version
Base.@static
```

## Versioning

```@docs
Base.VersionNumber
Base.@v_str
```

## Errors

```@docs
Expand Down
4 changes: 4 additions & 0 deletions doc/src/base/collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Fully implemented by:

```@docs
Base.in
Base.:∉
Base.eltype
Base.indexin
Base.unique
Expand Down Expand Up @@ -239,6 +240,9 @@ Base.symdiff
Base.symdiff!
Base.intersect!
Base.issubset
Base.:⊈
Base.:⊊
Base.issetequal
```

Fully implemented by:
Expand Down
2 changes: 1 addition & 1 deletion doc/src/manual/packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,7 @@ The first condition applies to any system but Windows and the second condition a
UNIX system besides OS X.

Runtime checks for the current version of Julia can be made using the built-in `VERSION` variable,
which is of type `VersionNumber`. Such code is occasionally necessary to keep track of new or
which is of type [`VersionNumber`](@ref). Such code is occasionally necessary to keep track of new or
deprecated functionality between various releases of Julia. Examples of runtime checks:

```julia
Expand Down
Loading

0 comments on commit 6291d3e

Please sign in to comment.