Creating an Icon list of a fixed size
The Icon function ``list(n, x)'' creates a list containing n elements, all equal to x. So, for example, this expression sets the variable ``totals'' to a list containing ten zeroes:
totals := list ( 10, 0 );You can also omit the second argument to the ``list()'' function, and each element will be undefined (that is, set to the null value; see `How does the null value work in Icon?'). For example, this expression sets the variable ``winners'' to a list of 86 copies of the null value ``&null'':
winners := list ( 86 );
Warning! This statement does not do what you think:
danger := list ( 5,  );You'd think it would set up a list containing five empty lists, but it doesn't. It sets up a list containing five pointers to the same empty list. Pages 76--77 of the Icon book have a good discussion of pointers; see `References for the Icon programming language'.
John Shipman, email@example.com
Last updated: 1996/01/06 21:12:57 UT