Set literals in Disco [006V]
We can write literal sets using curly braces and commas in between elements, just as in standard mathematical notation. Notice that the order in which we write the elements, or the number of copies we write of each element, does not matter.
Disco> {1,2,3}
{1, 2, 3}
Disco> {3,1,1,2}
{1, 2, 3}
Disco> {} -- this is how we write the empty set
{}We can also use ellipses to indicate an omitted sequence of elements. Notice that the number of dots in the ellipses, or whether you use commas and/or spaces before and after the ellipses, does not matter.
Disco> {1..5}
{1, 2, 3, 4, 5}
Disco> {1, ......., 5}
{1, 2, 3, 4, 5}
Disco> {1, 3, 5 ... 15}
{1, 3, 5, 7, 9, 11, 13, 15}
Disco> {8 ... 3}
{3, 4, 5, 6, 7, 8}
Disco> {5, 10, 15, ... 40}
{5, 10, 15, 20, 25, 30, 35, 40}
Disco> {1, 4, 9, ... 36}
{1, 4, 9, 16, 25, 36}The last few examples show that Disco can follow basic patterns when using ellipses. For example, {1, 3, 5 ...} will generate odd numbers, {8 ... 3} counts down instead of up, and {5, 10, ...} counts by fives. In the last example, we can even generate square numbers! See the Disco language reference documentation if you are interested to understand exactly what Disco is doing here: basically it is fitting a polynomial to the given points.