Next / Previous / Index / ITC Help System / Publications / Site map / NM Tech homepage

Creating an Icon list of a fixed size

Tech Computer Center logo

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'.
Next: Finding the size of an Icon list
See also: Using the list type in Icon
Previous: Creating an Icon list with specific contents
Site map
Index: Keyword index to help pages
Help: New Mexico Tech Information Technology and Communications: Help System
ITC Publications
To report a problem: File a ticket
Send mail to the User consultant on duty or call them at 575-835-5437
Home: About New Mexico Tech

John Shipman, john@nmt.edu
Last updated: 1996/01/06 21:12:57 UT
URL: http://www.nmt.edu/tcc/help/lang/icon/listfunc.html
QR two-dimensional bar code