Skip to content

Commit 02df6b6

Browse files
committed
Implement f.(args...) as a synonym for broadcast(f, args...), as discussed 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.:+
1 parent 2afff60 commit 02df6b6

17 files changed

+101
-84
lines changed

base/REPLCompletions.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function complete_symbol(sym, ffunc)
3232
if lookup_module
3333
# If we're considering A.B.C where B doesn't exist in A, give up
3434
isdefined(mod, s) || return UTF8String[]
35-
b = mod.(s)
35+
b = getfield(mod, s)
3636
if isa(b, Module)
3737
mod = b
3838
elseif Base.isstructtype(typeof(b))
@@ -261,8 +261,8 @@ function get_value(sym::Expr, fn)
261261
end
262262
fn, true
263263
end
264-
get_value(sym::Symbol, fn) = isdefined(fn, sym) ? (fn.(sym), true) : (nothing, false)
265-
get_value(sym::QuoteNode, fn) = isdefined(fn, sym.value) ? (fn.(sym.value), true) : (nothing, false)
264+
get_value(sym::Symbol, fn) = isdefined(fn, sym) ? (getfield(fn, sym), true) : (nothing, false)
265+
get_value(sym::QuoteNode, fn) = isdefined(fn, sym.value) ? (getfield(fn, sym.value), true) : (nothing, false)
266266
get_value(sym, fn) = sym, true
267267

268268
# Return the value of a getfield call expression
@@ -278,7 +278,7 @@ function get_type_call(expr::Expr)
278278
f_name = expr.args[1]
279279
# The if statement should find the f function. How f is found depends on how f is referenced
280280
if isa(f_name, TopNode)
281-
f = Base.(f_name.name)
281+
f = getfield(Base, f_name.name)
282282
found = true
283283
elseif isa(f_name, Expr) && f_name.args[1] === TopNode(:getfield)
284284
f, found = get_value_getfield(f_name, Main)
@@ -460,7 +460,7 @@ function completions(string, pos)
460460
end
461461
end
462462
end
463-
ffunc = (mod,x)->(isdefined(mod, x) && isa(mod.(x), Module))
463+
ffunc = (mod,x)->(isdefined(mod, x) && isa(getfield(mod, x), Module))
464464
comp_keywords = false
465465
end
466466
startpos == 0 && (pos = -1)

base/docs/Docs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const modules = Module[]
6868

6969
const META′ = :__META__
7070

71-
meta(mod) = mod.(META′)
71+
meta(mod) = getfield(mod, META′)
7272

7373
meta() = meta(current_module())
7474

base/docs/helpdb/Base.jl

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ asin
7373
7474
Subtype operator, equivalent to `issubtype(T1,T2)`.
7575
"""
76-
Base.(:(<:))
76+
Base.:(<:)
7777

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

235235
"""
236236
At_mul_B(A, B)
@@ -289,7 +289,7 @@ sortrows
289289
290290
Element-wise right division operator.
291291
"""
292-
Base.(:(./))
292+
Base.:(./)
293293

294294
"""
295295
IPv6(host::Integer) -> IPv6
@@ -572,7 +572,7 @@ ind2sub(a, index)
572572
573573
Element-wise multiplication operator.
574574
"""
575-
Base.(:(.*))
575+
Base.:(.*)
576576

577577
"""
578578
ror!(dest::BitArray{1}, src::BitArray{1}, i::Integer) -> BitArray{1}
@@ -783,7 +783,7 @@ julia> [1:5;] |> x->x.^2 |> sum |> inv
783783
0.01818181818181818
784784
```
785785
"""
786-
Base.(:(|>))
786+
Base.:(|>)
787787

788788
"""
789789
assert(cond)
@@ -922,7 +922,7 @@ diag
922922
923923
Element-wise exponentiation operator.
924924
"""
925-
Base.(:(.^))
925+
Base.:(.^)
926926

927927
"""
928928
isspace(c::Union{Char,AbstractString}) -> Bool
@@ -1213,7 +1213,7 @@ sizeof(::AbstractString)
12131213
12141214
See the [`is`](:func:`is`) operator.
12151215
"""
1216-
Base.(:(===))
1216+
Base.:(===)
12171217

12181218
"""
12191219
ReadOnlyMemoryError()
@@ -1702,7 +1702,7 @@ searchsorted
17021702
Right division operator: multiplication of `x` by the inverse of `y` on the right. Gives
17031703
floating-point results for integer arguments.
17041704
"""
1705-
Base.(:(/))
1705+
Base.:(/)
17061706

17071707
"""
17081708
connect([host],port) -> TCPSocket
@@ -2601,7 +2601,7 @@ reduce(op, itr)
26012601
26022602
Element-wise greater-than-or-equals comparison operator.
26032603
"""
2604-
Base.(:(.>=))
2604+
Base.:(.>=)
26052605

26062606
"""
26072607
stdm(v, m)
@@ -2754,7 +2754,7 @@ eachindex
27542754
27552755
Element-wise less-than comparison operator.
27562756
"""
2757-
Base.(:(.<))
2757+
Base.:(.<)
27582758

27592759
"""
27602760
UndefRefError()
@@ -3053,7 +3053,7 @@ rest
30533053
getfield(value, name::Symbol)
30543054
30553055
Extract a named field from a `value` of composite type. The syntax `a.b` calls
3056-
`getfield(a, :b)`, and the syntax `a.(b)` calls `getfield(a, b)`.
3056+
`getfield(a, :b)`.
30573057
"""
30583058
getfield
30593059

@@ -4309,7 +4309,7 @@ rot180(A, k)
43094309
43104310
Element-wise less-than-or-equals comparison operator.
43114311
"""
4312-
Base.(:(.<=))
4312+
Base.:(.<=)
43134313

43144314
"""
43154315
checkbounds(array, indexes...)
@@ -4709,7 +4709,7 @@ bkfact!
47094709
47104710
Exponentiation operator.
47114711
"""
4712-
Base.(:(^))(x, y)
4712+
Base.:(^)(x, y)
47134713

47144714
"""
47154715
^(s, n)
@@ -4721,7 +4721,7 @@ julia> "Test "^3
47214721
"Test Test Test "
47224722
```
47234723
"""
4724-
Base.(:(^))(s::AbstractString, n::Int)
4724+
Base.:(^)(s::AbstractString, n::Int)
47254725

47264726
"""
47274727
position(s)
@@ -5547,7 +5547,7 @@ istaskdone
55475547
55485548
Element-wise greater-than comparison operator.
55495549
"""
5550-
Base.(:(.>))
5550+
Base.:(.>)
55515551

55525552
"""
55535553
search(string, chars, [start])
@@ -5866,7 +5866,7 @@ get
58665866
58675867
Element-wise not-equals comparison operator.
58685868
"""
5869-
Base.(:(.!=))
5869+
Base.:(.!=)
58705870

58715871
"""
58725872
lufact!(A) -> LU
@@ -6428,7 +6428,7 @@ isdiag
64286428
64296429
Equivalent to `!is(x, y)`.
64306430
"""
6431-
Base.(:(!==))
6431+
Base.:(!==)
64326432

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

69326932
"""
69336933
mapreducedim(f, op, A, dims[, initial])
@@ -7240,7 +7240,7 @@ diagm
72407240
72417241
Element-wise subtraction operator.
72427242
"""
7243-
Base.(:(.-))
7243+
Base.:(.-)
72447244

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

72797279
"""
72807280
EnvHash() -> EnvHash
@@ -7844,7 +7844,7 @@ rpad
78447844
setfield!(value, name::Symbol, x)
78457845
78467846
Assign `x` to a named field in `value` of composite type. The syntax `a.b = c` calls
7847-
`setfield!(a, :b, c)`, and the syntax `a.(b) = c` calls `setfield!(a, b, c)`.
7847+
`setfield!(a, :b, c)`.
78487848
"""
78497849
setfield!
78507850

@@ -7880,7 +7880,7 @@ countlines
78807880
78817881
Matrix multiplication.
78827882
"""
7883-
Base.(:(*))(::AbstractMatrix, ::AbstractMatrix)
7883+
Base.:(*)(::AbstractMatrix, ::AbstractMatrix)
78847884

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

79027902
"""
79037903
.\\(x, y)
79047904
79057905
Element-wise left division operator.
79067906
"""
7907-
Base.(:(.\))(x,y)
7907+
Base.:(.\)(x,y)
79087908

79097909
"""
79107910
\\(x, y)
79117911
79127912
Left division operator: multiplication of `y` by the inverse of `x` on the left. Gives
79137913
floating-point results for integer arguments.
79147914
"""
7915-
Base.(:(\))(x::Number,y::Number)
7915+
Base.:(\)(x::Number,y::Number)
79167916

79177917

79187918
"""
@@ -7922,7 +7922,7 @@ Base.(:(\))(x::Number,y::Number)
79227922
79237923
Multiplication operator. `x*y*z*...` calls this function with all arguments, i.e. `*(x, y, z, ...)`.
79247924
"""
7925-
Base.(:(*))(x, y...)
7925+
Base.:(*)(x, y...)
79267926

79277927
"""
79287928
```
@@ -7936,7 +7936,7 @@ julia> "Hello " * "world"
79367936
"Hello world"
79377937
```
79387938
"""
7939-
Base.(:(*))(s::AbstractString, t::AbstractString)
7939+
Base.:(*)(s::AbstractString, t::AbstractString)
79407940

79417941
"""
79427942
complement!(s)
@@ -8380,7 +8380,7 @@ to a variable, it returns the module in which the variable was bound. It calls o
83808380
83818381
Returns a tuple containing the dimensions of `A`. Optionally you can specify the
83828382
dimension(s) you want the length of, and get the length of that dimension, or a tuple of the
8383-
lengths of dimensions you asked for.:
8383+
lengths of dimensions you asked for.
83848384
83858385
julia> A = rand(2,3,4);
83868386
@@ -8440,7 +8440,7 @@ airy
84408440
84418441
Boolean not.
84428442
"""
8443-
Base.(:(!))
8443+
Base.:(!)
84448444

84458445
"""
84468446
length(A) -> Integer
@@ -8533,7 +8533,7 @@ NullException
85338533
85348534
Element-wise equality comparison operator.
85358535
"""
8536-
Base.(:(.==))
8536+
Base.:(.==)
85378537

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

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

87638763
"""
87648764
match(r::Regex, s::AbstractString[, idx::Integer[, addopts]])
@@ -8880,7 +8880,7 @@ isa
88808880
88818881
Less-than-or-equals comparison operator.
88828882
"""
8883-
Base.(:(<=))
8883+
Base.:(<=)
88848884

88858885
"""
88868886
ProcessExitedException()
@@ -10010,7 +10010,7 @@ midpoints
1001010010
1001110011
Element-wise addition operator.
1001210012
"""
10013-
Base.(:(.+))
10013+
Base.:(.+)
1001410014

1001510015
"""
1001610016
reverseind(v, i)
@@ -10463,7 +10463,7 @@ iswritable
1046310463
1046410464
Bitwise or.
1046510465
"""
10466-
Base.(:(|))
10466+
Base.:(|)
1046710467

1046810468
"""
1046910469
yieldto(task, arg = nothing)
@@ -10656,7 +10656,7 @@ enumerate
1065610656
1065710657
Greater-than-or-equals comparison operator.
1065810658
"""
10659-
Base.(:(>=))
10659+
Base.:(>=)
1066010660

1066110661
"""
1066210662
dawson(x)
@@ -10700,7 +10700,7 @@ colon(start, step, stop)
1070010700
1070110701
Bitwise exclusive or.
1070210702
"""
10703-
Base.(:$)(x, y)
10703+
Base.:$(x, y)
1070410704

1070510705
"""
1070610706
getsockname(sock::Union{TCPServer, TCPSocket}) -> (IPAddr,UInt16)

0 commit comments

Comments
 (0)