blob: 306f7e846fa409ca95516e9fd767c6d84c4365ee (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
[Posted to info-tex on 4 Nov 91; see exercise.004]
**********************************************************************
*** Exercise 7 (hard):
In the September 1991 issue of Dr. Dobb's Journal, in an article
`Little Languages, Big Questions' (pp. 16--25), Ray Vald\'es
described a `little language' as a part of a more complex
application that is
partitioned into two (or more) nested components: a core module
that provides a primitive set of services for an application area
(the ``engine''), and a surrounding module that provides
programmatic access to these services. The surrounding module is
typically a language interpreter for a simple, easily parsed
computer language--a ``little language''.
Since TeX seems to fall into this category, I wonder if any Dr. Dobb's
readers who know TeX tried their hand at the challenge given in a
sidebar (`How Strong Is Your Little Language')?
[An] informal benchmark of a language's computational power is the
programming exercise that Ken Thompson (coauthor of Unix) used to
pass the time in college. ... The goal is to write the shortest
self-reproducing program: ``More precisely stated ... to write a
source program that, when compiled and executed, will produce as
output an exact copy of its source.''
When I tried it it turned out to be a real challenge for me. In the
Unix world, for conventional compiled languages, the problem as
originally stated can assume output on the `standard output' stream;
but TeX already clutters up standard output with some of its built-in
messages. This leaves three alternatives in refining the statement of
the problem to be meaningful for TeX:
1. Write a TeX program that includes the built-in messages in its
source in such a way that it exactly fulfills the the original problem
statement with standard output as the output stream.
2. Pretend the built-in messages don't exist and write a TeX program
that reproduces an exact copy of itself (with no extra garbage)
in the middle of the built-in messages.
3. Write on a different output stream.
Take your pick, any or all of the above, and see what you can come up
with. I have solutions for 2 and 3 but have not gotten around to really
thinking about 1 yet. I believe it will require at least a different
algorithm than the other 2, if it is not impossible.
**********************************************************************
|