The diff is the program
Watch / diffed
Filmed on the Apple IIe 80-column display. The same session on the Videx UltraTerm: same keys, same text.
The Videx UltraTerm was an 80-column video card for the Apple IIe, with its own video memory and character generator, real hardware scrolling and more screen modes than the IIe's own 80 columns. This demo runs on either display; the UltraTerm film shows the original Videx UltraTerm, emulated.
diff -e does not describe a change, it is the change: a script of ed commands, last line first. The demo makes a changed copy of a manual page, writes the edit script, hands it to ed, and shows that cmp — which said the files differ a moment ago — now says nothing. This is how changes were distributed before there was a patch.
What it types
Everything it types, in order. A line starting with $ is a command at the shell, RET included; keys lines are single keystrokes to a program (RET, ESC and the control keys are named).
$ cd /tmp $ cp /usr/man/GREP A $ sed 's/regular/REGULAR/;4d' A > B $ cmp A B $ diff -e A B > S $ cat S $ echo w >> S $ ed A < S $ cmp A B $ diff A B
Between steps it presses ^L to clear the screen.
What the captions say
- A diff is a program for ed. First, two files:
- A, and B, which is A with four changes.
- Before Larry Wall's patch (1984), a change could travel as an ed script.
- diff -e writes the edit script: ed commands, last line first.
- Add ed's w command, and hand the script to ed.
- ed says nothing. Raymond's Rule of Silence: no news is good news.
- Now A and B should be the same file.
- Silence. The diff was the program.
The gate that proves it
This film is made by site/demos/diffed.py. Run as assertions, the
same file is make check-demo-diffed, and it runs with the rest of the tests. It requires that the host finds exactly four changed lines between the two files; that cmp first says they differ; that the script holds exactly one command per changed line, bottom-up, at the line numbers the host computes from the same bytes; and that after ed both cmp and diff say nothing. The checks themselves were tested: with ed replaced by a copy of true the demo fails at "cmp says nothing"; with cmp replaced by true it fails at "cmp says A and B differ"; with diff replaced by cat it fails at "the script went to the file".
Transcript
The screen at every checkpoint the test checks, as the recorder saved it:
== host: A and B differ in exactly four lines (t=0.0 s)
$
== sed printed nothing (t=20.6 s)
$ cd /tmp
$ cp /usr/man/GREP A
$ sed 's/regular/REGULAR/;4d' A > B
$
== cmp before (t=22.7 s)
$ cd /tmp
$ cp /usr/man/GREP A
$ sed 's/regular/REGULAR/;4d' A > B
$ cmp A B
A B differ: char 80, line 4
$
== cmp says A and B differ (t=22.7 s)
$ cd /tmp
$ cp /usr/man/GREP A
$ sed 's/regular/REGULAR/;4d' A > B
$ cmp A B
A B differ: char 80, line 4
$
== the script went to the file (t=42.4 s)
$ diff -e A B > S
$
== cat S (t=44.0 s)
$ diff -e A B > S
$ cat S
56c
The matcher is the same basic REGULAR-expression engine
.
46c
REGULAR expression.
.
12c
for lines matching the REGULAR expression. Normally,
.
4d
$
== the script holds one command per changed line, bottom-up: 56c 46c 12c 4d (t=44.0 s)
$ diff -e A B > S
$ cat S
56c
The matcher is the same basic REGULAR-expression engine
.
46c
REGULAR expression.
.
12c
for lines matching the REGULAR expression. Normally,
.
4d
$
== each change but the delete ends with a dot (t=44.0 s)
$ diff -e A B > S
$ cat S
56c
The matcher is the same basic REGULAR-expression engine
.
46c
REGULAR expression.
.
12c
for lines matching the REGULAR expression. Normally,
.
4d
$
== echo printed nothing (t=53.9 s)
$ echo w >> S
$
== ed ran the script quietly (t=58.1 s)
$ echo w >> S
$ ed A < S
$
== cmp says nothing (t=69.4 s)
$ echo w >> S
$ ed A < S
$ cmp A B
$
== diff says nothing either (t=74.5 s)
$ echo w >> S
$ ed A < S
$ cmp A B
$ diff A B
$