News flash: I'm going to Australia in February, so this Web site may be switched off at any time.
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 endThe ``
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.
john@nmt.edu