News flash: I'm going to Australia in February, so this Web site may be switched off at any time.


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.
Next: Finding the size of an Icon list
See also: Using the Icon programming language
Previous: Creating an Icon list with specific contents

John W. Shipman, john@nmt.edu