4 ms·
Why would you want to replace an array reference by its contents; what does that even mean? In high level languages "array reference" and "array contents" are
by kazinator 4y ago
Why would you want to replace an array reference by its contents; what does that even mean?
In high level languages "array reference" and "array contents" are basically the same thing.
It looks like in Perl there a passing semantics whereby array objects, denoted by @, when passed into a function, automatically spread into multiple arguments. To pass the arrays as individual objects, they have to be wrapped in an additional level of boxing; the function then has to unbox the outer box to get to the regular box.
It would have been much wiser for arrays to just pass as encapsulated objects, and to have a special syntax for requesting an array to be spread into arguments when that is required.
In terms of the syntax for this feature, it really smells like it is driven not by considerations of what is readable, memorable and consistent but by the design process of "where in the grammar can I still get away with cramming a new operator token, such that there is no parsing conflict?" Kind of like, "how can I cram this camping chair into the packed closet, so that everything doesn't come crashing down, provided I slam the door fast enough?"
- colejohnson66 4y agoAgree, it’s confusing, but Perl is just confusing in general. As for a “spread” operator, JavaScript uses three periods to “spread” an array or object into a function’s parameters. I really like it.