dif.icn: Procedure to check for differences

link dif
August 14, 1996; Robert J. Alexander
This file is in the public domain.

     dif(stream, compare, eof, group)
             generates a sequence of differences between an  arbitrary
             number of input streams.  Each result is returned as a list
             of diff_recs, one for each input stream, with each diff_rec
             containing a list of items that differ and their position
             in the input stream.

The diff_rec type is declared as:

             record diff_rec(pos,diffs)

dif() fails if there are no differences, i.e. it produces an empty
result sequence.
____________________________________________________________

For example, if two input streams are:

     a b c d e f g h
     a b d e f i j

the output sequence would be:

     [diff_rec(3,[c]),diff_rec(3,[])]
     [diff_rec(7,[g,h]),diff_rec(6,[i,j])

The arguments to dif(stream,compare,eof,group) are:

     stream          A list of data objects that represent input streams
                     from which dif will extract its input "records".
                     The elements can be of several different types which
                     result in different actions, as follows:

                        Type                    Action
                     ===========     =============================
                     file            file is "read" to get records

                     co-expression   co-expression is activated to
                                     get records

                     list            records are "gotten" (get()) from
                                     the list

                     diff_proc       a record type defined in "dif" to
                                     allow a procedure (or procedures)
                                     suppled by dif's caller to be called
                                     to get records.  Diff_proc has two
                                     fields, the procedure to call and the
                                     argument to call it with.  Its
                                     definition looks like this:

                                        record diff_proc(proc,arg)


Optional arguments:

     compare         Item comparison procedure -- succeeds if
                     "equal", otherwise fails (default is the
                     identity "===" comparison).  The comparison
                     must allow for the fact that the eof object
                     (see next) might be an argument, and a pair of
                     eofs must compare equal.

     eof             An object that is distinguishable from other
                     objects in the stream.  Default is &null.

     group           A procedure that is called with the current number
                     of unmatched items as its argument.  It must
                     return the number of matching items required
                     for file synchronization to occur.  Default is
                     the formula Trunc((2.0 * Log(M)) + 2.0) where
                     M is the number of unmatched items.

Source code | Program Library Page | Icon Home Page