Skip to content

Commit 3531671

Browse files
committed
Merge pull request #15032 from stevengj/vectorize_dot
WIP: implement f.(args...) as a synonym for broadcast(f, args...)
2 parents 9ae220a + 8ad0eab commit 3531671

23 files changed

+202
-92
lines changed

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ New language features
77
* Generator expressions, e.g. `f(i) for i in 1:n` ([#4470]). This returns an iterator
88
that computes the specified values on demand.
99

10+
* Broadcasting syntax: ``f.(args...)`` is equivalent to ``broadcast(f, args...)`` ([#15032]).
11+
1012
* Macro expander functions are now generic, so macros can have multiple definitions
1113
(e.g. for different numbers of arguments, or optional arguments) ([#8846], [#9627]).
1214
However note that the argument types refer to the syntax tree representation, and not
@@ -20,6 +22,8 @@ New language features
2022

2123
* `PROGRAM_FILE` global is now available for determining the name of the running script ([#14114]).
2224

25+
* The syntax `x.:sym` (e.g. `Base.:+`) is now supported, and `x.(:sym)` is deprecated ([#15032]).
26+
2327
Language changes
2428
----------------
2529

@@ -212,6 +216,7 @@ Deprecated or removed
212216
[#14469]: https://github.com/JuliaLang/julia/issues/14469
213217
[#14759]: https://github.com/JuliaLang/julia/issues/14759
214218
[#14798]: https://github.com/JuliaLang/julia/issues/14798
219+
[#15032]: https://github.com/JuliaLang/julia/issues/15032
215220
[#15192]: https://github.com/JuliaLang/julia/issues/15192
216221
[#15242]: https://github.com/JuliaLang/julia/issues/15242
217222
[#15258]: https://github.com/JuliaLang/julia/issues/15258

base/REPLCompletions.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ function get_value(sym::Expr, fn)
251251
end
252252
fn, true
253253
end
254-
get_value(sym::Symbol, fn) = isdefined(fn, sym) ? (fn.(sym), true) : (nothing, false)
255-
get_value(sym::QuoteNode, fn) = isdefined(fn, sym.value) ? (fn.(sym.value), true) : (nothing, false)
254+
get_value(sym::Symbol, fn) = isdefined(fn, sym) ? (getfield(fn, sym), true) : (nothing, false)
255+
get_value(sym::QuoteNode, fn) = isdefined(fn, sym.value) ? (getfield(fn, sym.value), true) : (nothing, false)
256256
get_value(sym, fn) = sym, true
257257

258258
# Return the value of a getfield call expression
@@ -269,7 +269,7 @@ function get_type_call(expr::Expr)
269269
f_name = expr.args[1]
270270
# The if statement should find the f function. How f is found depends on how f is referenced
271271
if isa(f_name, TopNode)
272-
ft = typeof(Base.(f_name.name))
272+
ft = typeof(getfield(Base, f_name.name))
273273
found = true
274274
else
275275
ft, found = get_type(f_name, Main)
@@ -458,7 +458,7 @@ function completions(string, pos)
458458
end
459459
end
460460
end
461-
ffunc = (mod,x)->(isdefined(mod, x) && isa(mod.(x), Module))
461+
ffunc = (mod,x)->(isdefined(mod, x) && isa(getfield(mod, x), Module))
462462
comp_keywords = false
463463
end
464464
startpos == 0 && (pos = -1)

base/deprecated.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,24 @@ end
10931093
#15995
10941094
@deprecate symbol Symbol
10951095

1096+
#15032: Expressions like Base.(:+) now call broadcast. Since calls
1097+
# to broadcast(x, ::Symbol) are unheard of, and broadcast(x, ::Integer)
1098+
# are unlikely, we can treat these as deprecated getfield calls.
1099+
function broadcast(x::Any, i::Union{Integer,Symbol})
1100+
depwarn("x.(i) is deprecated; use getfield(x, i) instead.", :broadcast)
1101+
getfield(x, i)
1102+
end
1103+
# clearer to be more explicit in the warning for the Module case
1104+
function broadcast(m::Module, s::Symbol)
1105+
depwarn("$m.(:$s) is deprecated; use $m.:$s or getfield($m, :$s) instead.", :broadcast)
1106+
getfield(m, s)
1107+
end
1108+
# expressions like f.(3) should still call broadcast for f::Function,
1109+
# and in general broadcast should work for scalar arguments, while
1110+
# getfield is certainly not intended for the case of f::Function.
1111+
broadcast(f::Function, i::Integer) = invoke(broadcast, (Function, Number), f, i)
1112+
1113+
#16167
10961114
macro ccallable(def)
10971115
depwarn("@ccallable requires a return type", Symbol("@ccallable"))
10981116
if isa(def,Expr) && (def.head === :(=) || def.head === :function)

0 commit comments

Comments
 (0)