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


Generating the elements of an Icon list

Icon's ``!'' operator, applied to a list, generates the elements of that list. For example, this expression would write each element of list ``L'' on a separate line:

    every write ( ! L );
Here's another example. This program reverses the lines from its input by pushing them onto a stack, and then generating the stack's elements:
    procedure main()
      L  :=  [];    # Create an empty list
      while push ( L, read ( ) );  # Push each line
      every write ( ! L );         # Generate & write lines
    end
The ``while'' loop reads each lines and adds it to the front of the list ``L''. The ``!'' operator generates the elements of the list one at a time, and the ``every'' iterates over the generated values as they are written.
Next: Sorting an Icon list
See also: Using the Icon programming language
Previous: Using Icon lists as queues

John W. Shipman, john@nmt.edu