Finds the Longest Common Subsequence between
a-ls
and
b-ls
, comparing elements with
eq
(default
equal?
. Returns this sequence as a list, using the
elements from
a-ls
. Uses quadratic time and space.
(lcs-with-positions a-ls b-ls [eq])
Variant of
lcs
which returns the annotated sequence. The
result is a list of the common elements, each represented as a
list of 3 values: the element, the zero-indexed position in
a-ls
where the element occurred, and the position in
b-ls
.
Utility to run lcs on text.
a
and
b
can be strings or
ports, which are tokenized into a sequence by calling
reader
until
eof-object
is found. Returns a list of three values,
the sequences read from
a
and
b
, and the
lcs
result.
(write-diff diff [writer out])
Utility to format the result of a
diff
to output port
out
(default
(current-output-port)
). Applies
writer
to successive diff chunks.
writer
should be a
procedure of three arguments:
(writer subsequence type
out). subsequence
is a subsequence from the original input,
type
is a symbol indicating the type of diff: 'same
if this is part of the lcs, 'add
if it is unique to the
second input, or 'remove
if it is unique to the first
input. writer
defaults to write-line-diffs
,
assuming the default line diffs.
Equivalent to
write-diff
but collects the output to a string.
(write-line-diffs lines type out)
The default writer for
write-diff
, annotates simple +/-
prefixes for added/removed lines.
(write-line-diffs/color lines type out)
A variant of
write-line-diffs
which adds red/green ANSI
coloring to the +/- prefix.
(write-char-diffs chars type out)
A diff writer for sequences of characters (when a diff was
generated with
read-char
), enclosing added characters in
«...» brackets and removed characters in »...«.
(write-char-diffs/color chars type out)
A diff writer for sequences of characters (when a diff was
generated with
read-char
), formatting added characters in
green and removed characters in red.
(write-edits ls lcs [index writer out])
Utility to format the result of a
diff
with respect to a
single input sequence
ls
.
lcs
is the annotated common
sequence from
diff
or
lcs-with-positions
, and
index
is the index (0 or 1, default 1) of
ls
in the
original call. Since we have no information about the other
input, we can only format what is the same and what is different,
formatting the differences as either added (if
index
is 0)
or removed (if
index
is 1).
(edits->string ls lcs [type writer])
Equivalent to
write-edits
but collects the output to a string.
(edits->string/color ls lcs [type writer])
Equivalent to
write-edits
but collects the output to a
string and uses a color-aware writer by default. Note with a
character diff this returns the original input string as-is, with
only ANSI escapes indicating what changed.