Skip to content

A .+ B .+ C differs from @. A+B+C #29120

Open
@mbauman

Description

@mbauman

The .+ syntax lowers to two binary calls whereas the macro uses the n-ary parsing from +:

julia> Meta.@lower A .+ B .+ C
:($(Expr(:thunk, CodeInfo(
 1%1 = (Base.getproperty)(Base.Broadcast, :materialize)              │
 │   %2 = (Base.getproperty)(Base.Broadcast, :broadcasted)              │
 │   %3 = (Base.getproperty)(Base.Broadcast, :broadcasted)              │
 │   %4 = (%3)(+, A, B)                                                 │
 │   %5 = (%2)(+, %4, C)                                                │
 │   %6 = (%1)(%5)                                                      │
 └──      return %6                                                     │
))))

julia> Meta.@lower @. A + B + C
:($(Expr(:thunk, CodeInfo(
 1%1 = (Base.getproperty)(Base.Broadcast, :materialize)              │
 │   %2 = (Base.getproperty)(Base.Broadcast, :broadcasted)              │
 │   %3 = (%2)(+, A, B, C)                                              │
 │   %4 = (%1)(%3)                                                      │
 └──      return %4                                                     │
))))

I actually like the parsing of A .+ B .+ C better as it makes life easier for us to keep .+ associative with respect to range behaviors — we only define the two-argument flavors. Perhaps we should split the n-ary calls to binary ones in @.? Unfortunately, the macro cannot distinguish between @. A + B + C and @. (+)(A, B, C).

Metadata

Metadata

Assignees

No one assigned

    Labels

    broadcastApplying a function over a collection

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions