Skip to content

Commit

Permalink
Implement f.(args...) as a synonym for broadcast(f, args...), as disc…
Browse files Browse the repository at this point in the history
…ussed in #8450.

Also, support f.:x as a synonym for getfield(f, :x), so that one
no longer needs to do f.(:x).  For example, it was common to use
Base.(:+) and similar, and this can now be written Base.:+
  • Loading branch information
stevengj committed Feb 13, 2016
1 parent c205457 commit 2ac9c87
Show file tree
Hide file tree
Showing 17 changed files with 101 additions and 84 deletions.
10 changes: 5 additions & 5 deletions base/REPLCompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function complete_symbol(sym, ffunc)
if lookup_module
# If we're considering A.B.C where B doesn't exist in A, give up
isdefined(mod, s) || return UTF8String[]
b = mod.(s)
b = getfield(mod, s)
if isa(b, Module)
mod = b
elseif Base.isstructtype(typeof(b))
Expand Down Expand Up @@ -261,8 +261,8 @@ function get_value(sym::Expr, fn)
end
fn, true
end
get_value(sym::Symbol, fn) = isdefined(fn, sym) ? (fn.(sym), true) : (nothing, false)
get_value(sym::QuoteNode, fn) = isdefined(fn, sym.value) ? (fn.(sym.value), true) : (nothing, false)
get_value(sym::Symbol, fn) = isdefined(fn, sym) ? (getfield(fn, sym), true) : (nothing, false)
get_value(sym::QuoteNode, fn) = isdefined(fn, sym.value) ? (getfield(fn, sym.value), true) : (nothing, false)
get_value(sym, fn) = sym, true

# Return the value of a getfield call expression
Expand All @@ -278,7 +278,7 @@ function get_type_call(expr::Expr)
f_name = expr.args[1]
# The if statement should find the f function. How f is found depends on how f is referenced
if isa(f_name, TopNode)
f = Base.(f_name.name)
f = getfield(Base, f_name.name)
found = true
elseif isa(f_name, Expr) && f_name.args[1] === TopNode(:getfield)
f, found = get_value_getfield(f_name, Main)
Expand Down Expand Up @@ -460,7 +460,7 @@ function completions(string, pos)
end
end
end
ffunc = (mod,x)->(isdefined(mod, x) && isa(mod.(x), Module))
ffunc = (mod,x)->(isdefined(mod, x) && isa(getfield(mod, x), Module))
comp_keywords = false
end
startpos == 0 && (pos = -1)
Expand Down
2 changes: 1 addition & 1 deletion base/docs/Docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const modules = Module[]

const META′ = :__META__

meta(mod) = mod.(META′)
meta(mod) = getfield(mod, META′)

meta() = meta(current_module())

Expand Down
74 changes: 37 additions & 37 deletions base/docs/helpdb/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ asin
Subtype operator, equivalent to `issubtype(T1,T2)`.
"""
Base.(:(<:))
Base.:(<:)

"""
schedule(t::Task, [val]; error=false)
Expand Down Expand Up @@ -230,7 +230,7 @@ Evaluates the arguments to the function call, determines their types, and calls
Divide two integers or rational numbers, giving a `Rational` result.
"""
Base.(:(//))
Base.:(//)

"""
At_mul_B(A, B)
Expand Down Expand Up @@ -289,7 +289,7 @@ sortrows
Element-wise right division operator.
"""
Base.(:(./))
Base.:(./)

"""
IPv6(host::Integer) -> IPv6
Expand Down Expand Up @@ -572,7 +572,7 @@ ind2sub(a, index)
Element-wise multiplication operator.
"""
Base.(:(.*))
Base.:(.*)

"""
ror!(dest::BitArray{1}, src::BitArray{1}, i::Integer) -> BitArray{1}
Expand Down Expand Up @@ -783,7 +783,7 @@ julia> [1:5;] |> x->x.^2 |> sum |> inv
0.01818181818181818
```
"""
Base.(:(|>))
Base.:(|>)

"""
assert(cond)
Expand Down Expand Up @@ -922,7 +922,7 @@ diag
Element-wise exponentiation operator.
"""
Base.(:(.^))
Base.:(.^)

"""
isspace(c::Union{Char,AbstractString}) -> Bool
Expand Down Expand Up @@ -1213,7 +1213,7 @@ sizeof(::AbstractString)
See the [`is`](:func:`is`) operator.
"""
Base.(:(===))
Base.:(===)

"""
ReadOnlyMemoryError()
Expand Down Expand Up @@ -1702,7 +1702,7 @@ searchsorted
Right division operator: multiplication of `x` by the inverse of `y` on the right. Gives
floating-point results for integer arguments.
"""
Base.(:(/))
Base.:(/)

"""
connect([host],port) -> TCPSocket
Expand Down Expand Up @@ -2601,7 +2601,7 @@ reduce(op, itr)
Element-wise greater-than-or-equals comparison operator.
"""
Base.(:(.>=))
Base.:(.>=)

"""
stdm(v, m)
Expand Down Expand Up @@ -2754,7 +2754,7 @@ eachindex
Element-wise less-than comparison operator.
"""
Base.(:(.<))
Base.:(.<)

"""
UndefRefError()
Expand Down Expand Up @@ -3053,7 +3053,7 @@ rest
getfield(value, name::Symbol)
Extract a named field from a `value` of composite type. The syntax `a.b` calls
`getfield(a, :b)`, and the syntax `a.(b)` calls `getfield(a, b)`.
`getfield(a, :b)`.
"""
getfield

Expand Down Expand Up @@ -4309,7 +4309,7 @@ rot180(A, k)
Element-wise less-than-or-equals comparison operator.
"""
Base.(:(.<=))
Base.:(.<=)

"""
checkbounds(array, indexes...)
Expand Down Expand Up @@ -4709,7 +4709,7 @@ bkfact!
Exponentiation operator.
"""
Base.(:(^))(x, y)
Base.:(^)(x, y)

"""
^(s, n)
Expand All @@ -4721,7 +4721,7 @@ julia> "Test "^3
"Test Test Test "
```
"""
Base.(:(^))(s::AbstractString, n::Int)
Base.:(^)(s::AbstractString, n::Int)

"""
position(s)
Expand Down Expand Up @@ -5547,7 +5547,7 @@ istaskdone
Element-wise greater-than comparison operator.
"""
Base.(:(.>))
Base.:(.>)

"""
search(string, chars, [start])
Expand Down Expand Up @@ -5866,7 +5866,7 @@ get
Element-wise not-equals comparison operator.
"""
Base.(:(.!=))
Base.:(.!=)

"""
lufact!(A) -> LU
Expand Down Expand Up @@ -6428,7 +6428,7 @@ isdiag
Equivalent to `!is(x, y)`.
"""
Base.(:(!==))
Base.:(!==)

"""
trailing_ones(x::Integer) -> Integer
Expand Down Expand Up @@ -6927,7 +6927,7 @@ Collections should generally implement `==` by calling `==` recursively on all c
New numeric types should implement this function for two arguments of the new type, and
handle comparison to other types via promotion rules where possible.
"""
Base.(:(==))
Base.:(==)

"""
mapreducedim(f, op, A, dims[, initial])
Expand Down Expand Up @@ -7240,7 +7240,7 @@ diagm
Element-wise subtraction operator.
"""
Base.(:(.-))
Base.:(.-)

"""
imag(z)
Expand Down Expand Up @@ -7274,7 +7274,7 @@ arguments of the new type. Because of the behavior of floating-point NaN values,
implements a partial order. Types with a canonical partial order should implement `<`, and
types with a canonical total order should implement `isless`.
"""
Base.(:(<))
Base.:(<)

"""
EnvHash() -> EnvHash
Expand Down Expand Up @@ -7844,7 +7844,7 @@ rpad
setfield!(value, name::Symbol, x)
Assign `x` to a named field in `value` of composite type. The syntax `a.b = c` calls
`setfield!(a, :b, c)`, and the syntax `a.(b) = c` calls `setfield!(a, b, c)`.
`setfield!(a, :b, c)`.
"""
setfield!

Expand Down Expand Up @@ -7880,7 +7880,7 @@ countlines
Matrix multiplication.
"""
Base.(:(*))(::AbstractMatrix, ::AbstractMatrix)
Base.:(*)(::AbstractMatrix, ::AbstractMatrix)

"""
\\(A, B)
Expand All @@ -7897,22 +7897,22 @@ When `A` is sparse, a similar polyalgorithm is used. For indefinite matrices, th
factorization does not use pivoting during the numerical factorization and therefore the
procedure can fail even for invertible matrices.
"""
Base.(:(\))(A,B)
Base.:(\)(A,B)

"""
.\\(x, y)
Element-wise left division operator.
"""
Base.(:(.\))(x,y)
Base.:(.\)(x,y)

"""
\\(x, y)
Left division operator: multiplication of `y` by the inverse of `x` on the left. Gives
floating-point results for integer arguments.
"""
Base.(:(\))(x::Number,y::Number)
Base.:(\)(x::Number,y::Number)


"""
Expand All @@ -7922,7 +7922,7 @@ Base.(:(\))(x::Number,y::Number)
Multiplication operator. `x*y*z*...` calls this function with all arguments, i.e. `*(x, y, z, ...)`.
"""
Base.(:(*))(x, y...)
Base.:(*)(x, y...)

"""
```
Expand All @@ -7936,7 +7936,7 @@ julia> "Hello " * "world"
"Hello world"
```
"""
Base.(:(*))(s::AbstractString, t::AbstractString)
Base.:(*)(s::AbstractString, t::AbstractString)

"""
complement!(s)
Expand Down Expand Up @@ -8380,7 +8380,7 @@ to a variable, it returns the module in which the variable was bound. It calls o
Returns a tuple containing the dimensions of `A`. Optionally you can specify the
dimension(s) you want the length of, and get the length of that dimension, or a tuple of the
lengths of dimensions you asked for.:
lengths of dimensions you asked for.
julia> A = rand(2,3,4);
Expand Down Expand Up @@ -8440,7 +8440,7 @@ airy
Boolean not.
"""
Base.(:(!))
Base.:(!)

"""
length(A) -> Integer
Expand Down Expand Up @@ -8533,7 +8533,7 @@ NullException
Element-wise equality comparison operator.
"""
Base.(:(.==))
Base.:(.==)

"""
cfunction(function::Function, ReturnType::Type, (ArgumentTypes...))
Expand Down Expand Up @@ -8593,7 +8593,7 @@ intersect
Not-equals comparison operator. Always gives the opposite answer as `==`. New types should
generally not implement this, and rely on the fallback definition `!=(x,y) = !(x==y)` instead.
"""
Base.(:(!=))
Base.:(!=)

"""
@spawn
Expand Down Expand Up @@ -8758,7 +8758,7 @@ isprime(::BigInt, ?)
Greater-than comparison operator. Generally, new types should implement `<` instead of this
function, and rely on the fallback definition `>(x,y) = y<x`.
"""
Base.(:(>))
Base.:(>)

"""
match(r::Regex, s::AbstractString[, idx::Integer[, addopts]])
Expand Down Expand Up @@ -8880,7 +8880,7 @@ isa
Less-than-or-equals comparison operator.
"""
Base.(:(<=))
Base.:(<=)

"""
ProcessExitedException()
Expand Down Expand Up @@ -10012,7 +10012,7 @@ midpoints
Element-wise addition operator.
"""
Base.(:(.+))
Base.:(.+)

"""
reverseind(v, i)
Expand Down Expand Up @@ -10465,7 +10465,7 @@ iswritable
Bitwise or.
"""
Base.(:(|))
Base.:(|)

"""
yieldto(task, arg = nothing)
Expand Down Expand Up @@ -10658,7 +10658,7 @@ enumerate
Greater-than-or-equals comparison operator.
"""
Base.(:(>=))
Base.:(>=)

"""
dawson(x)
Expand Down Expand Up @@ -10702,7 +10702,7 @@ colon(start, step, stop)
Bitwise exclusive or.
"""
Base.(:$)(x, y)
Base.:$(x, y)

"""
getsockname(sock::Union{TCPServer, TCPSocket}) -> (IPAddr,UInt16)
Expand Down
Loading

0 comments on commit 2ac9c87

Please sign in to comment.