ABC Example: A Cross-reference Indexer

'Text files' are represented as tables of numbers to strings:
        HOW TO DISPLAY t:
           FOR name IN keys t:
              WRITE name<<10, t[name] /

        >>> DISPLAY poem
        1         I've never seen a purple cow
        2         I hope I never see one
        3         But I can tell you anyhow
        4         I'd rather see than be one
The following function takes such a document, and returns the cross-reference index of the document: a table from words to lists of line-numbers:
        HOW TO RETURN index doc:
           PUT {} IN where
           FOR line.no IN keys doc:
              TREAT LINE
           RETURN where
        TREAT LINE:
           FOR word IN split doc[line.no]:
              IF word not.in keys where:
                 PUT {} IN where[word]
              INSERT line.no IN where[word]
TREAT LINE here is a refinement, directly supporting stepwise-refinement. 'split' is a function that splits a string into its space-separated words:
        >>> WRITE split "Hello world"
        {[1]: "Hello"; [2]: "world"}

        >>> DISPLAY index poem
        But        {3}
        I          {2; 2; 3}
        I'd        {4}
        I've       {1}
        a          {1}
        anyhow     {3}
        be         {4}
        can        {3}
        cow        {1}
        hope       {2}
        never      {1; 2}
        one        {2; 4}
        purple     {1}
        rather     {4}
        see        {2; 4}
        seen       {1}
        tell       {3}
        than       {4}
        you        {3}