Ref vs zero-dimensional arrays?

Ref doesn’t really have anything to do with broadcasting. It’s just a convenient, short-named zero-dimensional container that doesn’t have the overhead of the Array header. As long as Ref is a zero-dimensional container, I don’t see any conflating of semantics. Now, that view isn’t entirely historically accurate, as Refs were indeed previously “hijacked” and special-cased to behave like 0-dimensional arrays only for the purposes of broadcast, but these days they really are 0-dimensional like and they just behave appropriately.

I was imagining that Ref would only be transiently visible to users until the &x syntax landed, but that got tied up and slogged down. I’d still love to see that, then the choice of how we implement scalars would be entirely internal. It’s indeed the &x syntax that could unites the ccall and broadcast use-cases.

You can also use (x,) or [x] as 1-tuples and 1-vectors also broadcast (almost) entirely like scalars. The tuple will of course be more efficient than the vector.

3 Likes