Scala is lacking so far a concise way to specify collection literals. This makes it an outlier compared to many other popular languages. We propose to change this by introducing a special syntax for such literals. The syntax is quite conventional: A sequence is written as a comma-separated list of elements enclosed in square brackets. For instance, here is a diagonal matrix of rank 3:
This pre-sip is a follow-on to a previous thread which received a large number of comments discussing many different alternatives. I am starting a new thread to focus on a concrete proposal that differs in some aspects from the original one. Some of the previously proposed alternatives are discussed below.
One reason Scala is such a late comer to collection literals is that it already offers with apply methods an alternative that is reasonably concise. For instance we’d express the diagonal matrix above in Scala like this:
This uses the standard convention of apply methods taking vararg arguments. Nevertheless, the new syntax is has clear advantages: