# recent broadcast changes (iterate by default), scalar struct, and \`@.\`

**URL:** <https://discourse.julialang.org/t/recent-broadcast-changes-iterate-by-default-scalar-struct-and/11178>\
**Category:** Internals & Design\
**Tags:** broadcast\
**Created:** [May 27, 2018, 3:48am UTC](https://discourse.julialang.org/t/recent-broadcast-changes-iterate-by-default-scalar-struct-and/11178 "2018-05-27T03:48:05Z")\
**Posts on this page:** 9\
**Page:** 4

<div class="post-metadata">

**Author:** ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)\
**Post date:** [January 3, 2019, 10:03pm UTC](https://discourse.julialang.org/t/recent-broadcast-changes-iterate-by-default-scalar-struct-and/11178/62 "2019-01-03T22:03:11Z")

</div>

I still think that [Broadcast had one job (e.g. broadcasting over iterators and generator) · Issue #18618 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/18618) should have been simply resolved as wontfix, despite the sensationalist issue title. For me, using broadcast with non-`AbstractArray` iterables is an extremely rare use case (honestly, not sure if I’ve ever done it). I’d gladly give that up to get the scalar-unless-`AbstractArray` behavior back.

---

<div class="post-metadata">

**Author:** ![Azamat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/azamat/32/6892_2.png) [@Azamat](https://discourse.julialang.org/u/Azamat)\
**Post date:** [January 3, 2019, 10:42pm UTC](https://discourse.julialang.org/t/recent-broadcast-changes-iterate-by-default-scalar-struct-and/11178/63 "2019-01-03T22:42:56Z")

</div>

I also think that “treat as scalar by default” is more sensible. If a user defines an iterator it makes sense for him to define `broadcastable` method for his type as part of the interface for an iterator. But under the current default user has to define `broadcastable` for his scalar `struct`. 😕

If you read the discussion in issue [18618](https://github.com/JuliaLang/julia/issues/18618), the majority seems to be in favor of “treat as scalar by default” option, so it is surprising to me that the current “treat as iterator by default” option was chosen…

The strongest arguments in that discussion, IMO, were given by @stevengj and are as follows:

> `broadcast` is for containers with shapes, and defaults to treating objects as scalars. `map` is for containers without shapes, and default to treating objects as iterators.

> the whole point of `broadcast` is to be able to “broadcast” scalars to match containers, e.g. to do `["bug", "cow", "house"] .* "s" --> ["bugs", "cows", "houses"]` . This is fundamentally different from the behavior of `map`.

> I dislike any design that requires us to define a method for a type to be treated as a scalar. That should be the default.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [January 4, 2019, 4:12pm UTC](https://discourse.julialang.org/t/recent-broadcast-changes-iterate-by-default-scalar-struct-and/11178/64 "2019-01-04T16:12:19Z")

</div>

It’s water under the bridge at this point, since the default can’t be changed in Julia 1.x without breaking compatibility. The current behavior wasn’t my first choice, but I can certainly live with it.

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [January 4, 2019, 4:46pm UTC](https://discourse.julialang.org/t/recent-broadcast-changes-iterate-by-default-scalar-struct-and/11178/65 "2019-01-04T16:46:16Z")

</div>

We can change the default in cases where it errors. Those are the cases you and others aren’t satisfied with.

---

<div class="post-metadata">

**Author:** ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)\
**Post date:** [January 4, 2019, 7:49pm UTC](https://discourse.julialang.org/t/recent-broadcast-changes-iterate-by-default-scalar-struct-and/11178/66 "2019-01-04T19:49:24Z")

</div>

Can this be done in a way that preserves the metasemantic construct underpinning Julia’s broadcasting?

---

<div class="post-metadata">

**Author:** ![BioTurboNick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bioturbonick/32/6380_2.png) [@BioTurboNick](https://discourse.julialang.org/u/BioTurboNick)\
**Post date:** [January 9, 2019, 4:18pm UTC](https://discourse.julialang.org/t/recent-broadcast-changes-iterate-by-default-scalar-struct-and/11178/67 "2019-01-09T16:18:01Z")

</div>

For the record, this issue also affects @enum broadcasts, which might be a more common use than trying to broadcast across a singular struct.

---

<div class="post-metadata">

**Author:** ![Azamat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/azamat/32/6892_2.png) [@Azamat](https://discourse.julialang.org/u/Azamat)\
**Post date:** [January 9, 2019, 6:36pm UTC](https://discourse.julialang.org/t/recent-broadcast-changes-iterate-by-default-scalar-struct-and/11178/68 "2019-01-09T18:36:27Z")

</div>

Can you give minimum working example that demonstrates this?

---

<div class="post-metadata">

**Author:** ![BioTurboNick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bioturbonick/32/6380_2.png) [@BioTurboNick](https://discourse.julialang.org/u/BioTurboNick)\
**Post date:** [January 9, 2019, 6:45pm UTC](https://discourse.julialang.org/t/recent-broadcast-changes-iterate-by-default-scalar-struct-and/11178/69 "2019-01-09T18:45:06Z")

</div>

```julia
@enum Foo foo1 foo2
b = Vector{Foo}(undef, 2)
b .= foo1

# Error!

Broadcast.broadcastable(a::Foo) = (a,)
b .= foo1

# Success!

```

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [January 9, 2019, 7:18pm UTC](https://discourse.julialang.org/t/recent-broadcast-changes-iterate-by-default-scalar-struct-and/11178/70 "2019-01-09T19:18:37Z")

</div>

> [@BioTurboNick](#):
>
> For the record, this issue also affects `@enum` broadcasts

Seems like a bug (easily fixable): [Enum should be a scalar for broadcast · Issue #30669 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/30669)

[Previous page](https://discourse.julialang.org/t/recent-broadcast-changes-iterate-by-default-scalar-struct-and/11178.md?page=3)
