[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

12.41 text.diff - Calculate difference of text streams

Module: text.diff

This module calculates the difference of two text streams or strings, using util.lcs (See section util.lcs - The longest common subsequence).

Function: diff src-a src-b :key reader eq-fn

Generates an "edit list" from text sources src-a and src-b.

Each of text sources, src-a and src-b, can be either an input port or a string. If it is a string, it is converted to a string input port internally. Then, the text streams from both sources are converted to sequences by calling reader repeatedly on them; the default of reader is read-line, and those sequences are passed to lcs-edit-list to calculate the edit list. The equality function eq-fn is also passed to lcs-edit-list.

An edit list is a set of commands that turn the text sequence from src-a to the one from src-b. See the description of lcs-edit-list for the detailed explanation of the edit list.

(diff "a\nb\nc\nd\n" "b\ne\nd\nf\n")
  (((- 0 "a"))
   ((- 2 "c") (+ 1 "e"))
   ((+ 3 "f")))
Function: diff-report src-a src-b :key reader eq-fn writer

A convenience procedure to take the diff of two text sources and display the result nicely. This procedure calls lcs-fold to calculate the difference of two text sources. The meanings of src-a, src-b, reader and eq-fn are the same as diff’s.

Writer is a procedure that takes two arguments, the text element and a type, which is either a symbol +, a symbol -, or #f. If the text element is only in src-a, writer is called with the element and -. If the text element is only in src-b, it is called with the element and +. If the text element is in both sources, it is called with the element and #f. The default procedure of writer prints the passed text element to the current output port in unified-diff-like format:

(diff-report "a\nb\nc\nd\n" "b\ne\nd\nf\n")


- a
- c
+ e
+ f

[ < ] [ > ]   [ << ] [ Up ] [ >> ]

This document was generated on July 19, 2014 using texi2html 1.82.