Skip to content

Commit

Permalink
Merge pull request #15032 from stevengj/vectorize_dot
Browse files Browse the repository at this point in the history
WIP: implement f.(args...) as a synonym for broadcast(f, args...)
  • Loading branch information
JeffBezanson committed May 9, 2016
2 parents 9ae220a + 8ad0eab commit 3531671
Show file tree
Hide file tree
Showing 23 changed files with 202 additions and 92 deletions.
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ New language features
* Generator expressions, e.g. `f(i) for i in 1:n` ([#4470]). This returns an iterator
that computes the specified values on demand.

* Broadcasting syntax: ``f.(args...)`` is equivalent to ``broadcast(f, args...)`` ([#15032]).

* Macro expander functions are now generic, so macros can have multiple definitions
(e.g. for different numbers of arguments, or optional arguments) ([#8846], [#9627]).
However note that the argument types refer to the syntax tree representation, and not
Expand All @@ -20,6 +22,8 @@ New language features

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

* The syntax `x.:sym` (e.g. `Base.:+`) is now supported, and `x.(:sym)` is deprecated ([#15032]).

Language changes
----------------

Expand Down Expand Up @@ -212,6 +216,7 @@ Deprecated or removed
[#14469]: https://github.com/JuliaLang/julia/issues/14469
[#14759]: https://github.com/JuliaLang/julia/issues/14759
[#14798]: https://github.com/JuliaLang/julia/issues/14798
[#15032]: https://github.com/JuliaLang/julia/issues/15032
[#15192]: https://github.com/JuliaLang/julia/issues/15192
[#15242]: https://github.com/JuliaLang/julia/issues/15242
[#15258]: https://github.com/JuliaLang/julia/issues/15258
Expand Down
8 changes: 4 additions & 4 deletions base/REPLCompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,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 @@ -269,7 +269,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)
ft = typeof(Base.(f_name.name))
ft = typeof(getfield(Base, f_name.name))
found = true
else
ft, found = get_type(f_name, Main)
Expand Down Expand Up @@ -458,7 +458,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
18 changes: 18 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,24 @@ end
#15995
@deprecate symbol Symbol

#15032: Expressions like Base.(:+) now call broadcast. Since calls
# to broadcast(x, ::Symbol) are unheard of, and broadcast(x, ::Integer)
# are unlikely, we can treat these as deprecated getfield calls.
function broadcast(x::Any, i::Union{Integer,Symbol})
depwarn("x.(i) is deprecated; use getfield(x, i) instead.", :broadcast)
getfield(x, i)
end
# clearer to be more explicit in the warning for the Module case
function broadcast(m::Module, s::Symbol)
depwarn("$m.(:$s) is deprecated; use $m.:$s or getfield($m, :$s) instead.", :broadcast)
getfield(m, s)
end
# expressions like f.(3) should still call broadcast for f::Function,
# and in general broadcast should work for scalar arguments, while
# getfield is certainly not intended for the case of f::Function.
broadcast(f::Function, i::Integer) = invoke(broadcast, (Function, Number), f, i)

#16167
macro ccallable(def)
depwarn("@ccallable requires a return type", Symbol("@ccallable"))
if isa(def,Expr) && (def.head === :(=) || def.head === :function)
Expand Down
Loading

0 comments on commit 3531671

Please sign in to comment.