JuliaLang/julia — pull request #6839 by simonbyrne (2014-05-14 10:36:45+00:00)
Title: RFC: inplace! macro for broadcasting operations

This adds `@inplace!` macro for replacing calls to `broadcast!`:
```julia
julia> import Base.Broadcast.@inplace!

julia> x = ones(3,3)
3x3 Array{Float64,2}:
1.0 1.0 1.0
1.0 1.0 1.0
1.0 1.0 1.0

julia> @inplace! x = x .+ x
3x3 Array{Float64,2}:
2.0 2.0 2.0
2.0 2.0 2.0
2.0 2.0 2.0

julia> macroexpand(:(@inplace! a = b .+ c))
:(begin # broadcast.jl, line 452:
Base.Broadcast.broadcast!(+,a,b,c)
end)
```

Two issues that would probably need to be addressed:

1) The parser doesn't allow *n*-ary `.+` and `.*` operations (unlike `+` and `*`), so
```julia
julia> macroexpand(:(@inplace! a = b .+ c .+ d))
:(begin # broadcast.jl, line 452:
Base.Broadcast.broadcast!(+,a,b .+ c,d)
end)
```
I could make the macro recursive, but I first thought I would find out if it would be worth considering a change to the parser?

2) At the moment, numbers cannot be `broadcast` (though they can be wrapped in an array).
```julia
julia> @inplace! x = x .+ 2.0
ERROR: no method check_broadcast_shape((Int64,Int64), Array{Float64,2}, Float64)
in _F_ at broadcast.jl:73
in broadcast! at broadcast.jl:227

julia> @inplace! x = x .+ [2.0]
3x3 Array{Float64,2}:
4.0 4.0 4.0
4.0 4.0 4.0
4.0 4.0 4.0
```