You are on page 1of 8

for source needle, destination needle

METAMAGICAL and helping needle. Here goes:


To move a tower of height n
THEMAS from sn to dn, making use of hn:
if n = 1,
then just carry that one disk
directly from sn to dn;
otherwise,
In which a discourse on the language Lisp do the following three steps:
(1) move a tower of height
concludes with a gargantuan Italian feast n —
1 from sn to hn,
making use of dn;
(2) carry 1 disk from sn to dn;
(3) move a tower of height
by Douglas R. Hofstadter n —
1 from hn to dn,
making use Of sn.

Here the steps labeled 1 and 3 are the


is this. Suppose the 64-disk tower of two recursive calls; skirting paradox,
month I described fidouard Lu-
last cas's Tower of Brahma puzzle,
_* where the object is to transfer a
tower of 64 gold disks from one dia-
Brahma
schematic
starts out
top in the illustration on
picture
on needle
this
representing
all,
a. At
page
all
relying
the
is
64
a
they seem to call on thevery ability they
arehelping to define. The saving feature
is that they involve n
of n. Note that in step
— 1 disks instead
1 hn plays the
mond needle to another, making use of a disks by amere 4. First of on
dn plays the
third needle on which disks can be your presumed 63 -disk-moving ability, "destination" role while
hnplays the
placed temporarily. The disks must be transfer 63 disksfrom needle a to needle "helper"role. And in step 3 "help-
picked up and moved one at a time, the c, using needle b as your "helping nee- "source" role while sn plays the
is shown er" role. Since the whole thing is recur-
only other constraint being that no disk dle." How the setup looks sec-
ond from the top in the illustration. sive, every needle will be switching hats
may ever be placed on a smaller one. many times over in the course of the
(Note that 4 plays the role of 64 in my
The problem I posed for readers was to the puz-
come up with a recursive description, originalpicture, so that 3 plays the role transfers. That is the beauty of
1 not zle and in a way it is also the beauty
expressed as a function in the computer of 63, but for some reason does
language Lisp, of how to accomplish play the role of 61. Isn't that peculiar?) of recursion.
Now, simply pick up the one remain- How do we make the transition from
this goal(and thereby, according to the simple:
priests of Brahma, end the world). ing a disk—the biggest disk of all—and English to Lisp? It is quite
plunk it down on needle b, as is shown
I pointed out that the recursion is evi- (def move-tower
dent enough: in order to transfer 64 third from the top.
disks from one needle to another, using Now you can see how easy itwillbe to (lambda (n sn dn hn)
finish up: simply reexploityour 63 -disk (cond
a third, it suffices to know how to trans- ((eq n 1) (carry-one-disk sn dn))
fer 63 disks from oneneedle to another, ability to transfer that pileon c back to b,
using a third. To recapitulate the idea, it this time using aas the "helping needle." (t (move-tower (subl n) sn hn dn)
Notice how in this maneuver needle a (carry-one-disk sn dn)
plays the helping role needle c played in (move-tower (subl n) hn dn sn)))))
010 I I the preceding 63 -disk maneuver. A split
1 00 I I secondbefore the last disk is put inplace Where are the Lisp equivalents of the
000 I 000 I I
the situation is as it is shown at the bot- English words "to," and "mak-
I dis-
tom in the illustration. Why before it is ing use of"? They seem to have
0000 I 0000 I
after? Because the appeared. Then how can the Lisp ge-
a b c in place? Why not
entire world then turns to dust, and it is nie know which needle is to play which
too hard to drawdust. role at each stage? The answer is that
I I I Now, someone might complain that I the information is conveyedpositionally.
I I 010 left out all the hard parts: "You just There are, in this function
I I 00 1 00
magically assumed an ability to move four parameters: one integer and three
000 1 000 three
0000 1 0000
63 disks." So it may seem, but there is "dummy needles." The first of the
I
needles is the source, the second the des-
a fa c nothing magical about such an assump-
all, in order to move 63 you tination and the third the helper. Thus in
tion. After
(following
merely need to know how to move 62. the initial list of parameters
I I 1 And to move 62, you merely need to the "lambda") they are in the order "sn
I I 010 know how to move 61. On it goes down dn hn". In the first recursive call, the
I I 00 I 00
line, until you bottom out at the Lisp translation of step 1, they are in the
0000 1 0000 000 I 000
the
I "embryonic case" of the Tower ofBrah- order "sn hn dn", showing how hn and
a fa c ma puzzle, the 1-disk puzzle. Now, I ad- dn have switched hats. In the second re-
cursive call, the Lisp translation of step
mit that you have to keep track of where
sn have
00
you are in the process, which may be a 3, you can see that hn and
bit tedious, but it is merelybookkeeping. switched hats.
I I I In principle you now could actually car- The point is that the atom names "sn",
I 00 I 00 i "dn" and "hn" carry no intrinsic mean-
I ry out the entire process—if you were
I 000 I 000 ing to the genie. They could as wellhave
I 0000 1 0000 I bent on seeing the world end!
As our first approximation of a Lisp been "apple", "banana" and "cherry".
a fa c function let us write an English descrip- Their meanings are denned operational-
tion of the method. Let us call the three ly, by the places where they appear in
The Tower of Brahma puzzle with four disks needles "sn", "dn" and "hn", standing the various parts of the function defini-

14
tion. Hence it would have been a gross
(ab ac be ab ca cb ab ac be ba ca be ab ac be ab ca cb ab ca be ba ca cb
blunder to have written, for instance, be ba ca cb ab ca be ba ca be
ab ac be ab ca cb ab ac be ba ca be ab ac
"(move-tower (subl n) sn dn hn)" as ab ac be ab ca cb ab ac be ba ca be ab ac be ab ca cb ab ca be ba ca cb
Lisp for step 1, because that contains no ab ac be ab ca cb ab ca be ba ca be ab ac be ba ca cb ab ca be ba ca cb
ab ac be ab ca cb ab ac be ba ca be ab ac be ab ca cb ab ca be ba ca cb
indication that hn and dn must switch ca be
roles in that step. ab ac be ab ca cb ab ac be ba ca be ab ac be ba ca cb ab ca be ba
ab ac be ab ca cb ab ac be ba ca be ab ac be ba ca cb ab ca be ba ca cb
An important questionremains. What ab ac be ab ca cb ab ea be ba ca be abac be ba ca cb ab ca be ba ca be
happens when the friendly Lisp genie ab ac be ab ca cb ab ac be ba ca be ab ac be ab ca cb ab ca be ba ca cb
comes to a step that says "carry-one- ab ac be ab ca cb ab ac be ba ca be ab ac be ba ca cb ab ca be ba ca be
disk"?Does it suddenly zoom off to the ab ac be ab ca cb ab ac be ba ca be ab ac be ab ca cb ab ca be ba ca cb
ab ac be ab ca cb ab ca be ba ca be ab ac be ba ca cb ab ca be ba ca cb
temple at Benares and literally heft a ab ac be ab ca cb ab ac be ba ca be ab ac be ab ca cb ab ca be ba ca cb
solid gold disk? Or more prosaically, ab ac be ab ca cb ab ca be ba ca be ab ac be ba ca cb ab ca be ba ca be
does it pick up a plastic disk on a table ab ac be ab ca cb ab ac be ba ca be ab ac be ba ca cb ab ca be ba ca cb
and transfer it from one plastic needle ab ac be ab ca cb ab ca be ba ea be ab ac be ba ca cb ab ca bc.ba ca cb
ab ac be ab ca cb ab ac. be ba ca be ab ac be ab ca cb ab ca be ba ca cb
to another? In other words, does some ab ac be ab ca cb ab ac be ba ca be ab ac be ba ca cb ab ca be ba ca be
physical action, rather than amere com- ab.ae be ab ca cb ab ac be ba ca be ab ac be ab ca cb ab ca be ba ca cb
putation, take place? ab ac be ab ca cb ab ca be ba ca be ab ac be ba ca cb ab ca be ba ca cb
ab ac be ab ca cb ab ac be ba ca be ab ac be ab ca cb ab ca be ba ca cb
Well, in theory it is quite possible. In
even in practice the executionof a ab ac be ab ca cb ab)
Lisp command could actually cause a
mechanical arm to move to a specific The Lisp geniefires back the moves to solve a 9-high Tower of Brahma puzzle
location, to pick up whatever its me-
chanical hand grasps, to carry that ob-
ject to another specific locationand then then the value returned by "(cons apple the recursive part of move-tower will
to release it. In these days of industrial (cons banana (cons cherry nil)))" will return. Well, that is pretty easy. We sim-
robots there is nothing science-fictional be the list "(1 2 3)". There is, how- ply want it to return a sandwichlike list
about it. In the absence of a mechanical ever, a shorter way to get the same in which the values of the two recursive
arm and hand to move physical disks, result, namely to write "(list apple ba- calls flank the value of the single call to
however, what could it mean? nana cherry)". It returns the same value. carry-one-disk. And so we can modify
Oneobvious and closelyrelated possi- Similarly, if the atoms "sn" and "dn" our previous recursive definition very
bility is for there to be a display of the are bound respectively to "a" and "b", slightly, by adding the word "list":
puzzle on a screen, and for "carry-one- then execution of the command "(list
disk" to cause a picture of a hand to sn dn)" will return "(a b)". The func- (def move-tower
move, to appear to grasp a disk, pick it tion "list" is an unusual function in that (lambda (n sn dn hn)
up and replace it somewhere else. That it takes any number of arguments at (cond
would amount to simulating the puzzle all—even none, so that "(list)" returns ((eq nl) (carry-one-disk sn dn))
graphically, which can be done with the value of nil! (t
varying degrees of realism. Now let us tackle the problem ofwhat (list
Suppose, however, we do not have value we want the function called "car- (move-tower (subl n) sn hn dn)
fancy graphics hardwareor software at ry-one-disk" to return. It has two pa- (carry-one-disk sn dn)
our disposition. Suppose all we want is rameters that represent needles, and (move-tower (subl n) hn dn sn))))))
to create a printed recipe telling us how ideally we should like it to return a sin-
to moveour organic, humarihands gle atom made out of those needles' Now let us conduct a little exchange
in order to solve the puzzle. Thus in the names, such as "ab" or "12". For the with the Lisp genie:
case of a three-disk puzzle the desired moment it will be easier if we assume
recipe might read "ab ac be ab ca cb that the needle names are the numbers —
> (move-tower 4 'a 'b 'c)
ab", or equally well "12 13 23 12 31 1, 2 and 3. In this case to makethe num- (((ac ab cb) ac (ba be ac))
32 12". What could help us to reach ber 12 out of 1 and 2 it suffices to do a ab
this humbler goal? bit of arithmetic: multiply the first num- ((cb ca ba) cb (ac ab cb)))
If we had a program that moved an ber by 10 and add on the second. Here —
>
arm, we would be concerned not with is the Lisp for that:
the value it returned but with the pat- Smashing! It actually works! Isn't that
terned sequence of "side effects" it car- (def carry-one-disk pretty? In last month's column this list
ried out. Here, in contrast, we are con- (lambda (sn dn) was called "brahma".
cerned only with the value our program (plus (times 10 sn) dn))) Suppose we wanted to suppress all
is going to return: a patterned list of at- the inner parentheses, so that just a long,

oms. The list for n 3 has got to bebuilt On the other hand, if the needle names uninterrupted sequence of atoms would
up from two lists for n = 2. This idea are non-numeric atoms, we can use a be printed out. For instance, we would
was shown at the end of last month's standard Lisp function called "concat", get "(ac ab cb ac ba be ac ab cb ca
column: whichtakes the values of its arguments ba cb ac ab cb)" instead of the intri-
(any number, as with "list") and concat- cacy of brahma. It would be slightlyless
ab ac be ab ca cb ab enates them all to make one big atom. informative but more impressive in its
Thus "(concat'con 'cat 'c 'nate)" returns opaqueness. In this case we would not
In order to set groups apart in Lisp, the atom "concatenate". In such a case want to use the function "list" to make
rather than using wider spaces we use we could write: our sandwich of three values but would
parentheses. Hence our goal for n= 3 have to use some other function that
might be to produce the sandwichlike (def carry-one-disk would remove the parenthesesfrom the
list "«ab ac be) ab (ca cb ab))". One (lambda (sn dn) (concat sn dn))) two flanking recursive values.
way to produce a. list out of its compo- This is acase where the standard Lisp
nents is to use "cons" repeatedly. There- Either way we have solved the bottom- function "append" comes in handy. It
fore if the values of the atoms "apple", line half of the move-tower problem. splices any number of lists together,
"banana" and "cherry" are 1, 2 and 3, The other half of the problem is what dropping their outermost parentheses
19
as it does so. Thus "(append '(a (b)) n = 2 consists of one atom followed by The embryonic case Occurs when
'(c) nil '(d c))" yields the five-element two lists. To fix this we can turn each longlist is nil. Then nothing happens,
list "(a (b) c d c)" rather than the four- entry in the tableinto a list by enclosing and so our answer should be nil.
element list "((a (b)) (c) nil (d c))", it in one outermost pair of parentheses. The recursive case involves building
which would be yielded if "list" rath- Now our goal is consistent with Lisp. a more complex answer out of a simpler
er than "append" had appeared in the How do we attain it? one assumed to be given. We can fall
function position. Using append and a Recursive thinking tells us that the back on our "(a b a)" example for this.
slightly modified version of carry-one- bottom line, or embryonic case, occurs We built the complex answer "(1 2 3
disk to work with it, we can formulate a when n equals 0, and that otherwise the b 1 2 3)" out of the simpler answer
final definition of move-tower that does nth line is made from the line before it "(b 1 2 3)" by appending "(1 2 3)" to
what we want: by replacing the atom "tato", wherever it. On the other hand, we could consid-
it occurs, with the list "(tato (and tato er "(b 1 2 3)" itself to be a complex
(def move-tower only))", but without its outermost pa- answer built out of the simpler answer
(lambda (n sn dn hn) / rentheses. We can write this up: "(1 2 3)" by consing "b" onto it. Why
(cond does one involve appending and the oth-
((eq n 1) (carry-one-disk sn dn)) (def tato-expansion er involve consing? Simply because the
(t (lambda (n) first case involves the atom "a", which
(append (cond does get replaced, whereas the second
(move-tower (subl n) sn hn dn) ((eq n 0) '(tato)) involves the atom "b", which does not
(carry-one-disk sn dn) (t get replaced. This observation enables
(move-tower (subl n) hn dn sn)))))) (replace us to attempt to write down a recursive
'tato definition of "replace", as follows:
(def carry-one-disk '(tato (and tato only))
. (lambda (sn dn) (list (concat sn dn)))) (tato-expansion (subl n))))))) (def replace
(lambda (atm lyst longlist)
To test this out I asked the Lisp genie The only thing is that we have not (cond
to solve a 9-highTower of Brahma puz- specified what we mean by "replace". ((null longlist) nil)
zle. What it shot back at me, almost in- We must be very careful in defining ((eq (car longlist) atm)
stantaneously, is at the top of the pre- how to carry out our "replace" opera- (append
ceding page. tion. Look at any line of the "tato" table lyst
We have just been through a rather and you will see that it contains one (replace atm lyst (cdr longlist))))
sophisticated and brain-taxing example more element than the preceding line. (t
of recursion. Now let us take a look a at Why is this? Because the atom "tato" (cons
recursion that offers us a different kind gets replaced each time by a two-ele- (car longlist)
of challenge. This recursion comesfrom ment list whose parentheses, as I point- (replace atm lyst (cdr longlist)))))
an offhand remark I made in the last ed out above, are dropped in the act of ))
column. I used the odd variable name replacement. It is this parenthesis drop-
"tato", mentioning that it is a recursive ping that is the sticky point. A less tricky As you can see, there is an embryonic
acronym standing for "tato (and tato example of such parenthesis-dropping case (where longlist equals nil) and then
only)". Using this fact you can expand replacement than the recursive one in- one recursive case featuring "append"
"tato" any number of times. The sole volving "tato" would be "(replace 'a and onerecursive case featuring "cons".
principle is that each occurrence of '(1 2 3) '(a b a))", whose value should Now let us try out this definition on a
"tato" on a given level is replaced by the be "(1 2 3 b 1 2 3)". Rather than exact new example:
two-part phrase "tato (and tato only)" substitution of a list for an atom, this
to make the next level. How it goes is kind of replacement involves splicing or — > (replace 'a '(1 2 3) '(a (a) b a))
(1 2 3 (a) b 1 2 3)
shown in the illustration below. For us appending inside a long list.
the challenge is to write a Lisp function Let us try to specify in Lisp—using re-— >

that returns the value of "tato" after n cursion as usual just what we mean by
Whoops! It almostworked, except that
recursive expansions, for any n. It is "replacing" all occurrences of the atom
irrelevant that for n much bigger than 3 "atm" by a list called "lyst", inside a one of the occurrences of "a" was com-
the whole thing gets ridiculously large. long list called "longlist". This is a good pletely missed. This means that in our
We are theoreticians! puzzle for you to try. Let me give you a definition of "replace" we must have
There is only one problem: any Lisp hint: See how the answer for argument overlooked some eventuality. Indeed, if
function must return a single Lisp struc- "(a b a)" is built out of the answer for you go back, you will see that an unwar-
ture (an atom or a list) as its value, and argument "(b a)". Also look at other ranted assumptionslipped inright under
the entries in our table do not satisfy this simple cases like that, moving back our nose, namely that the elements of
criterion. For instance, the entry for down toward the embryonic case. longlist are always atoms. We ignored
the possibility that longlist might con-
tain sublists. What to do in such a case?
n=o : tato The answer: Do the replacement inside
those sublists as well. Andinside sublists
n=l : tato of sublists too—and so on. Can you fig-
(and tato only)
ure out a way to fix up the definition?
n=2 : tato We have seen a recursion before
(and tato only) where all parts on all levels of a struc-
(and tato (and tato only) only) ture needed to be explored; it was the
tato
function "atomcount" last month, in
n=3:
(and tato only) which we did a simultaneous recursion
(and tato (and tato only) only) on both "car" and "cdr". The recursive
(and tato (and tato only) (and tato (and tato only) only) only) line ran "(plus (atomcount (car s))
(atomcount (cdr s)))". Here it will be
A short table of recursive expansions of the Lisp variable designated "tato" quiteanalogous. We shall have a recur-

20
siveline featuring two calls on "replace", about mutually recursive acronyms? sideration, attention, or concern full of
one involving the car of longlist and one This could mean, for instance, two acro- fond or tenderfeeling or the quality,
involving the cdr, instead of just one in- nyms each of which contains a letter state, or instance of being faithful to,
volving the cdr. This makes perfect standing for the other acronym. An ex- thosepersons or ideals that one is under
sense when you think about it. Suppose ample would be the pair of acronyms obligation to defend or support, or the
you wanted to replace all the unicorns in "NOODLES" and stand- condition, quality or state of being wor-
Europe with porpuquines. One way to ing respectively for: thy of trust, or a strongly felt fond or
achieve this nefarious goal would be to tenderfeeling to a creature or creatures
split Europe into two pieces: Portugal "NOODLES (oodles of delicious of or characteristic of a person or per-
(Europe's car) and the remainder (Eu- LINGUINI), elegantly served" sons, that lives or exists, or is assumed
rope's cdr). After replacing all the uni- to do so, particularly as separated or
corns in Portugal with porpuquines, and "luscious itty-bitty NOODLES.got marked off by differences from that
also all the unicorns in the rest of Eu- usually in Naples, Italy" which is conceived, spoken or re-
rope with porpuquines, youwould final- ferred to as existing as an individual en-
ly recombine the two new pieces into a Notice, incidentally, that "NOODLES" tity, or from any living organism inferi-
reunified Europe. (This is supposed to is not only indirectly recursive but also or in rank, dignity, or authority, typical-
suggest a "cons" operation.) Of course, directly so. There is nothing wrong with ly capable of moving about but not
to carry out this dastardly operation on that. of making its own food by photosyn-
Portugal an analogous splitting and re- In general the notion of mutual recur- thesis."
joining would have to take place—and sion means a system of arbitrarily many Isn't it romantic? It certainly makes
so on. That suggests our recursive line interwoven structures each of which is "love" ever more mysterious. Stuart
will look like this: defined in terms of one or more mem- in his lucid classic on semantics,
bers of the system (possibly including The Tyranny of Words, does a similar
(cons (replace 'unicorn itself). If we are speaking of a family exercisefor "mind"and shows its opaci-
'(porpuquine) of mutually recursive acronyms, this ty equally well.- Of course, concrete
(car geographical-unit)) means a collection of words in any one words as well as abstractones get caught
(replace 'unicorn of which letters can stand for any word in this vortex of confusion. My favorite
(porpuquine) in the family. example is one.I discovered while look-
(cdr geographical-unit))) I have to admit that this specific no- ing through a French dictionary many
tion of mutually recursive acronyms is years ago. It defined the verb clocher ("to
more elegantly and more generally: not particularly useful in any practi- limp") as marcher en boitant (roughly
cal sense. It is nonetheless quite useful "to walk while hobbling") and boiter
(cons (replace atm lyst (ear longlist)) as a droll example of a very common ("to hobble") as clocher en marchant ("to
(replace atm lyst (cdr longlist))) abstract phenomenon. Who has not limp whilewalking"). This eagerlearner
at some time mused about the inevita- of French was helped precious little by
This "cons" line will cover the case ble circularity of dictionary definitions? that particular pair of definitions.
where longlist's car is nonatomic as well Anyone can see that all words eventual- But let us return to mutuallyrecursive
as the case where it is atomic but not ly are defined in terms of some funda- acronyms. I put quite a bit of effort into
equal to atm. In order to make thiswork mental set that is not further reducible working out a family of them, and to my
we need to augment the embryonic case but simply goes round and round end- surprise they wound up dealing most-
slightly: we shall say that when longlist lessly. You can amuse yourself by look- ly (although by no means exclusively!)
is not a list but an atom, "replace" has ing up the definition of a common word with Italian food. It all began when, in-
no effect on longlist at all. Conveniently in a dictionary and replacing the main spired by "tato", I chose the similar
this subsumes the earlier "null" line, and words in it by their definitions. I once word "tomato" and then decided to use
so we can drop that one. If we put all of carried this process out for "love," de- its plural, coming up with this meaning
this together, we come up with a new, fined as "a strong affection for or at- for "tomatoes":
improved definition: tachment or devotion to a person or
persons," substituting for "strong," "af- TOMATOES on MACARONI
(def replace "attachment," "devotion" and (and TOMATOES only),
(lambda (atm lyst longlist) "person" and coming up with this con- exquisitely SPICED
(cond coction: "A morally powerful mental
((atom longlist) longlist) state or tendency, having strength of The capitalizedwords within the phras-
((eq (car longlist) atm) character or will or affectionatere- es are those that are also acronyms.
(append gard, or loyalty, faithfulness or deep af- Here is the rest of my mutually recur-
lyst fection to, a human being or beings, es- sive family:
(replace atm lyst (cdr longlist)))) pecially as distinguishedfrom a thing or
(t lower animal." MACARONI:
(cons Not being satisfied with that, I carried MACARONI and CHEESE
(replace atm lyst (car longlist)) the entire process a step further. This (a REPAST of Naples, Italy)
(replace atm lyst (cdr longlist))))) was my result: "A set of circumstances
)) or attributes characterizing a person or REPAST:
thing at a given time in, with, or by the rather extraordinaryPASTA
Now when we say "(tato-expansion 2)" conscious or unconscious together as a and typical
to the Lisp genie, it will print out for us unit full of or having a specific ability or
the list "(tato (and tato only) (and tato capacity in amanner relating to, dealing CHEESE:
(and tato only) only))". with, or capable of making the distinc- havarti,Emmentaler -
Well, well. Isn't this a magnificent ac- tion between right and wrong in con- (particularlySHARP Emmentaler)
complishment? If it seems less than duct, or an inclination to moveor act in
magnificent, perhaps we can carry it a aparticular direction or way, having the SHARP:
step further. A recursive acronym one— state or quality of being strong in moral strong, hearty andrather pungent
containing a letter standing for the acro- strength, self-discipline, or fortitude, or
nym itself—can be amusing, but what the act orprocess of volition or con- SPICED:

21
sweetlypickled in CHEESE GARLIC: would make sense to say, "If you've seen
ENDIVE dressing green and red LASAGNE one rhubarb, you've seen them all."But
in CHEESE if we allow some randomness to enter
ENDIVE: the decision making about spawning, we
egg dipped Any gourmet can see that little attempt can get many varieties of rhubarb, all
in vinegar eggnog has been made to have each term de- bearing some telltale resemblance to
fined by its corresponding phrase; it is one another but at a much more elusive
NOODLES: simply associated more or less arbitrari- level of perception.
NOODLES (oodles of delicious ly with the phrase. How can we do it? The ideal concept
LINGUINI), elegantlyserved What happens if we begin to expand to bring to bear here is that of the ran-
some word, say "pasta"?At first we get dom-number generator,which serves as
LINGUINI: simply "PASTA and SAUCE (that's the computationalequivalent of a coin
LAMB CHOPS ALL!)". The next stage yields "PASTA flip ora dice throw.We shall let all deci-
(including NOODLES), and SAUCE (that's ALL!) and SHAD sions about whether or not to expand a
got usually in northern Italy and unusual COFFEE (eccellente!) given acronym depend on the outcome
(that's a luscious lunch)". We could ob- of such a virtual coin flip. At early stages
PASTA: viously go on expanding acronymsfor- of expansion we shall set things up so
PASTA and SAUCE (that's ALL!) ever, or at least until we filled the uni- that the coin will be very likely to come
verse to its very brim with mouth-water- up heads (do expand); at later stages it
ALL!: ing descriptions of Italian food. But will be increasingly likely to come up
a lusciouslunch what if we were less ambitious and tails (no expansion). The Lisp function
wanted merely to fill half a page or so "rand" will be employed for this. It
SAUCE: with such a description? How might we takes no arguments, and each time it is
SHAD and unusual COFFEE find a way to haltthis seeminglybottom- called it returns a new real number
(eccellente!) less recursion in midcourse? somewhere between0 and 1, unpredict-
The key word here is "bottomless," ably. (This is an exaggeration.It is actu-
SHAD: and the answer it implies is: Put in a ally 100 percent predictableif youknow
SPAGHETTI, heated al dente mechanism to allow the recursion to how it is computed, but since the algo-
bottom out. The bottomlessness comes rithm is rather obscure, for most pur-
SPAGHETTI: from the fact that at every stage every poses and for most observers the behav-
standard always good, hot acronym is allowed to expand,that is, to ior of the function will be so erratic that
particularly (twist,then ingest) spawn further acronyms. What if in- it counts as being totally random. The
stead wekept tight control of the spawn- story of random-number generation is
COFFEE: ing process, being generous in the first quite a fascinating one and would be an
choice of fine few "generations" and gradually letting article in itself.)
particularly ESPRESSO fewer and fewer acronymsspawnproge- If we want an event to happen with a
ny as the generationsgot later? It would probability of 60 percent, first we ask
ESPRESSO: be similar to a redwood tree in a rand for a value. If the value turns out to
excellent, strong, powerful, rich which begins with a single "branch" (its be .6 or below, we go ahead, otherwise
suppressing sleep trunk), and that branch spawns "prog- we do not. Since over a long period of
outrageously eny," namely the first generation of time rand sprays its outputs uniformly
smaller branches, and they in turn over the interval between 0 and 1, we
BASTA!: spawn ever more progeny—but eventu- shall indeed get the go-ahead 60 percent
belly all stuffed (tummy ache!) ally a natural bottoming out comes as a of the time.
consequence of the fact that teeny twigs So much for random decisions. How
LAMB CHOPS: simply cannot branch further. (Some- do we get an acronym to expand when it
LASAGNE and meatballs, how in the course of evolution trees is told to? That is not too hard. Suppose
casuallyheaped onto seem to have got their wires crossed, we let each acronym be a Lisp
PASTA SAUCE since for them bottoming out generally as in the following example:
takes place at the top.)
LASAGNE: If this process were completely regu- (def tomatoes
LINGUINI and SAUCE lar, all redwood trees would look exact- (lambda ()
and GARLIC ly alike and onecould agree with former '(tomatoes on macaroni
(NOODLES everywhere!) Governor Reagan's memorable dictum (and tomatoes only)
"If you've seen one redwood tree, exquisitely spiced))))
RHUBARB: you've seen them all." Unfortunately
heated under butter redwood trees (and maybe some other The function "tomatoes" takes no argu-
and RHUBARB (BASTA!) things) are trickier than Governor Rea- ments and simply returns the list of
gan realized, and we have to learn to words it expands into. Nothing could be
RAVIOLI: deal with a variety of things that go by simpler.
RIGATONI and vongole in oil, the same name. The variety is caused by Now suppose we have a variable
lavishly introduced the introductionof randomness into the called "acronym" whose value is some
choices of whether to branch or not to —
particular acronym but we do not
RIGATONI: branch, what angle to branch at, what know which one. How could we get that
rich ItalianGNOCCHI size branch to grow and so on. acronym to expand? The way we have
and TOMATOES Similar remarks apply to the "trees" set it up the acronymmust act as afunc-
(or NOODLES instead) of mutually recursive acronyms. If in tion call. In orderfor any atomto invoke
expanding "tomatoes" we always made a function it must be the car of a list, as
GNOCCHI: exactlythe same control decisionsabout in the examples "(plus 2 2)", "(rand)"
GARLIC NOODLES which acronyms to expand when, there and "(rhubarb)". If we were to write
over crisp would be oneand only one type of "rhu- "(acronym)", the literal atom "acro-
heated immediately barb" expansion, so that here too it nym" wouldbe taken by the Lisp genie

22
as a function name. That, however, To be exact, we can define the function in northern Italy), elegantlyserved over
would be a misunderstanding. It is cer- "lower" as follows: crisp cheese, heated immediatelyand to-
tainly not the atom "acronym" that we matoes on macaroni and cheese (a re-
want to make serve as a function name, (def lower (lambda (x) (times x .8))) past of Naples, Italy) (and tomatoes
but its value, be it "macaroni", "cheese" only), exquisitely sweetly pickled in
or what have you. Thus each time an acronym expands, its cheese endive dressing (or noodles in-
In order to accomplish this we resort progeny are only .8 times as likely to stead) and vongolein oil, lavishly intro-
to a little trick. If the value of the atom expand as it was. This means acronyms duced, heated under butter andrich Ital-
"acronym" is "rhubarb" and if I write nested deep enough have a vanishingly ian gnocchi and tomatoes (or noodles
"(listacronym)", the value the genie will small probability of spawning further instead) and vongole in oil, lavishly in-
return to me willbe the list "(rhubarb)". progeny. You could use any reducing troduced, heatedunder butter and riga-
The genie, however, will simply see this factor; there is nothing sacred about .8 toni and vongole in oil, lavishly intro-
as an inert piece of Lispstuff rather than except that it seems to yield good re- duced, heated under butter and ravioli,
as a littlecommand I should like to have sults for me. heated under butter and rich Italiangar-
executed. It cannot read my mind. How The only remaining undescribed lic noodles over crisp cheese, heated im-
do I get it to perform the desired opera- function inside the definition above is mediately and tomatoes (or noodles in-
tion? The answer is that I remember the "is-acronym". Its name is pretty self-ex- stead) and vongolein oil, lavishly intro-
function called "eval", whichmakes the planatory. First the function tests to see duced, heated under butter and ravioli,
genie look on a given data structure as a if its argument is an atom; if it is not, the heated under butter andrhubarb (basta!)
wish to be executed. In this case I need function returns nil. If the argument is (basta!) (basta!) (basta!) (belly all stuffed
merely say "(eval(list acronym))"and I an atom, the function goes on to see (tummy ache!)) (basta!))
shall get the list "(ravioli, heated under whether that atom has a function defini-
butterandrhubarb (basta!))". And if the tion, in particular a definition with the Can you figure out which acronym
acronym had had a different value, the form of an acronym. If the atom has this gastronomicalmonstrosity grewout
genie would have handed me a differ- such a is-acronymreturns the of? As you can see, Lisp is hardly the
ent list. value t; otherwise it returns nil. Precise- computer languageto learn if you want
We now have just aboutenough ideas ly howthis is done depends on your spe- to lose weight. One final exampleof the
to build afunction capable of expanding cific variety of Lisp, which is whyI have glories of recursive spaghetti is given
mutually recursive acronyms into long not shown it explicitly. In Franz Lisp herewith, expanded from a different
but finite phrases whose sizes and struc- only one line is needed. starting point:
tures are determined by many "flips" of You may have noticed that there are
the "rand" coin. Instead of stepping you two cond clauses in close proximity that (macaroniand cheese (a rather extraor-
through the construction of this func- begin with "t". How come one "other- dinary pasta and sauce, typical of Na-
tion I shall simply display it and let you wise" follows so closely on the heels of ples, Italy) and cheddar, havarti, Em-
peruse it. It is modeled very closely on another one? Actually they belong to mentaler (particularly sharp Emmental-
the earlier function "replace": different conds, one nested inside the er) (a rather extraordinary pasta and
other. The first "t" (belonging to the in- shad and unusual coffee (eccellente!)
(def expand ner cond) applies to a case where we (that's a luscious lunch) and sauce
(lambda (phrase probability) know we are dealing with an acronym (that's all!) and shad and unusual choice
(cond but where our random coin, instead of of fine particularly espresso (ec-
((atom phrase) phrase) coming down heads, has come down cellente!) (that's all!) and sauce (that's a
((is-acronym (car phrase)) tails (which amounts to a decision not to luscious lunch) and spaghetti, heated al
(cond expand); the second "t" (belonging to dente and unusual choice offine
((lessp (rand) probability) the outer cond) applies to a case where particularly excellent, strong, powerful,
(append we have discovered we are simply not rich espresso, suppressing sleep outra-
(expand (eval (list (car phrase))) dealingwith an acronym at all. geously (eccellente!), typical of Naples,
(lower probability)) The inner logic of "expand", when it Italy))
(expand (cdr phrase) probability))) is scrutinized carefully, makes perfect
(t sense. On the other hand, no matter The "expand" function exploits one
(cons (car phrase) how carefully you scrutinize it, the out-
of the most powerful features of Lisp.
(expand (cdr phrase) put produced by "expand" using this That is the ability of a Lisp program to
probability))))) "famiglia" of acronyms remains quite take data structures it has created and
(t silly. Here is an example: treat them as pieces of code (that is, give
(cons them to the Lisp genie as commands).
(expand (car phrase) (rich italian green and red linguini and Here it was done in a most rudimentary
(lower probability)) shad and unusual choice of fine way. An atom was wrappedin parenthe-
(expand (cdr phrase) probability)))) particularly excellent, strong, powerful, ses and the resulting minuscule list was
)) rich espresso, suppressing sleep outra- then evaluated, or "eval'd", as Lispers'
geously (eccellente!) and green and red jargonhas it. The work involved in man-
Note that "expand" has two param- lasagne in cheese (noodles everywhere!) ufacturing the data structure was next to
eters. One parameter represents the in cheddar, havarti, Emmentaler (par- nothing in this instance, but in other in-
phrase to be expanded, the other repre- ticularly sharp Emmentaler) noodles stances elaborate pieces of structure can
sents the probability of expanding any (oodles of delicious linguini), elegantly be "consed up", thenhanded to the Lisp
acronyms that are top-levelmembersof served(oodles of deliciouslinguini), ele- genie for "eval'ing".Such pieces of code
the given phrase. (Thus the value of the gantly served(oodlesof delicious lingui- might be new function definitions or any
atom "probability"willalways be a real ni and sauce and garlic (noodles(oodles number ofother things. The main idea is
number between0 and 1.)As in the red- of delicious linguini), elegantly served that in Lisp one has the ability to "ele-
wood-tree example, theexpansionprob- everywhere!) and meatballs, casually vate" an inert, information-containing
ability should decrease as the calls get heaped onto pasta and sauce(that's all!) data structure to the level of an "ani-
increasinglyrecursive. This is why lines and sauce (that's a luscious lunch) sauce mate agent," where it becomes a ma-
that call for the expansion of (car (including noodles (oodles of delicious nipulator of inert structures itself. This
phrase) do so with a lowered probability. linguini), elegantly served), got usually program-data cycle, or loop, can con-
24
80 " CO., tinue on and on, with structures reach- autonomously, is a "kernel"; then you
ing out, twisting back and indirectly can begin to lift yourself by your own
modifying themselves or structures re- bootstraps. For children it is an exciting

After
lated to them: thing when, as they read, they begin to
Certain types of inert, or passive, in- learn new phrases all by themselves,
formation-containing data structures simply by encountering them several
are sometimes referred to as "declara- times in succession. Their vocabulary

the day's
tiveknowledge"— "declarative" because begins to grow by leaps and bounds. So
theyoften have aform abstractlyresem- it is once there is a Lisp kernel in a sys-
bling that of a declarative sentence, and tem; the rest of the Lisp interpreter can
"knowledge" because they encodefacts be written in Lisp and usually is.
about the world, accessible by looking The fact that one can easily write the

hassle in an index in somewhat the way "book- Lisp interpreter in Lisp is no mere fluke
learned" facts are accessible to a human of some peculiarly introverted fact
being. In contrast, animate, or active, about Lisp. The reason it is easy is that,
pieces of code are referred to as "pro- because of its program-data loop, Lisp

and cedural knowledge"—"procedural" be-


cause they define sequences of actions
("procedures") that actuallymanipulate
data structures, and "knowledge" be-
lends itself to writing interpreters for
all kinds of computer languages. This
means Lisp can serve as a basis on which
one can build other languages.

hustle, cause they can be viewed as embodying


the program's set of skills, something
like a human being's unconscious skills
that were once learned through long
To put it more vividly, suppose you
have designed on paper a new language
called "Flumsy." If you really know
how Flumsy should work, it should not

trya rote drillsessions. Sometimes these con-


trasting knowledge types are referred
to as "knowledge that" and "knowl-
edge how."
be too hard for you to write an interpret-
er for itin Lisp. Onceyour Flumsy inter-
preter is implemented, it becomes in es-
sence a new genie to which you can give

soothing
This distinction should remind biolo- wishes in Flumsy and that will in turn
gists of the distinction between genes, communicate those wishes to the Lisp
which are relatively inert structures in- genie in Lisp. Of course, all the mech-
side the cell, and enzymes, which are anisms allowing the Flumsy "meta-

change
anything but inert. Enzymes are the ani- genie" to talk with the Lisp genie are
mate agents of the cell; they transform themselves being carried out by the
and manipulate all the inert structures Lisp genie. Is this a mere facade? Is talk-
in indescribably sophisticated ways. ing Flumsy really just a way of talking
Moreover,Lisp's loop of program and Lisp in disguise?

ofpace. data should remind biologistsof the way


genes dictate the form of enzymes and
enzymes manipulate genes (among oth-
er things). Thus Lisp's procedural-de-
clarative program-data loop provides a
Well, when the U.S. arms negotiators
talk with their Russian counterparts
through an "interpreter, are they really
just speaking Russian in disguise? Or is
the crux of the matter whether the inter-
primitive but very useful and tangible preter's native language was English or
exampleof oneof the most fundamental Russian, on which the other language
patterns at the base of life: the ability of was built as a second one? And suppose
passive structures to control their own you find out that actually the interpret-
destiny, by creating and regulating ac- er's native language was Lithuanian,
tive structures whoseform they dictate. that she learned English only as an ado-
We have been talking all along about lescent and then learnedRussian by tak-
the Lisp genie as a mysterious given ing high school classes taught in En-
agent, without asking where it is to be glish? Will you then think that when she
found or what makes it work. It turns speaks Russian, she is actually speaking
out that one of Lisp's most exciting English in disguise, or worse, that she is
properties is that one can describe with actually speaking Lithuanian, doubly
ease the Lisp genie's complete nature in disguised?
Lisp itself. In other words, the Lisp in- Analogously, you might find that the
terpreter can be easily written down in Lisp interpreter is actually written in
Lisp. Of course, if there is no Lisp inter- Pascal or some other computer lan-
preter to run that Lisp interpreter, it guage.And then someone could strip off
might seem like an absurd and pointless the Pascal facade as well, revealing to
exercise,a bit like having a description you that all instructions are reallybeing
in flowery English telling foreigners executed in machine language, so that
howbest to learn English. It is not, how- you are fooling yourself completely if
ever, as silly as that makes it sound. you think the machine is talking Flum-
In the first place, if you know enough sy,Lisp, Pascal or any otherhigher-level
English, you can "bootstrap" your way computer language!
further into English; there is a point be- When one interpreter runs on top of

JohnJameson
yond which explanationswritten in En- another, there is always the question
glish aboutEnglish are indeed quiteuse- of what level one chooses not to look
ful. What is more, that point is not too below. I personally seldom think about
Imported Irish Whiskey far beyond the beginning level. There- what underlies the Lisp interpreter, so
fore all you need to acquire and that when I am dealing with the Lisp

26
system, I feel as if I am talking with yond what I have described so be-
"someone" whose "native language" is cause it is more than just a language for
Lisp. Similarly, when I am dealing with writing programs. It includes an editing
INVEST people, I seldom think about what their
brains are composed of; I do not reduce
program, with which one can create and
modify one's programs (and text as
them mentally to piles of patterned neu- well), a debugging program, with which
YOURSELF ron firings. It is natural to my perceptual
system to recognize them at a certain
one can easily localize one's errors and
correct them, and many other
level and not to look below that level. all designed to be compatible with one
If someone were to write a pro- another and with an overarching "Lisp
gram that could deal in Chinese with philosophy."
simple questions and answers about res- Such machines, although theyare still
taurant visits, and if that program were expensive and somewhat developmen-
written in the hypothetical language tal, are rapidly becoming cheaper and
"SEARLE" (for "Simulated East-Asian more available. They are put out by var-
Restaurant-Lingo Expert"), I could ious new companies such as LMI (LISP
choose to view the system either as gen- Machine, Inc.), Symbolics, Inc., both of
uinely speaking Chinese (assuming it Cambridge, Mass., and older companies
gave a creditable and not too slow per- such as Xerox. Lisp is also available on
formance) or as genuinely speaking most personalcomputers; youneed only
SEARLE. I can shift my point of view at look at any issue of the current micro-
will. The one I adopt is governed most- computer magazines to find advertise-
ly by pragmatic factors, such as which ments for it.
subject area I am currently more inter- Why, in conclusion, is Lisp popularin
ested in (Chinese restaurants or how artificial intelligence? There is no single
grammars work), how closely matched answer, or evena simple answer. Would
the given level's speed is to that of my it be valid to say Lisp is "the language
own brain and, not least, whether I hap- of thought"? Certainly not. AI people
pen to be more fluent in Chinese or in might have said so 10 or 20 years ago,
SEARLE. If to me Chinese is a mere but few would be so bold today. One
bunch of squiggles and squoggles, I may reason Lisp has remained so popular is,
optfor theSEARLE viewpoint; if on the as I wrote in my first Lisp column, that
other hand SEARLE is amere bunch of Lisp is crisp. Indeed, Lisp can be so ele-
A windmill to pump water for "salt farm- confusing technical expressions, I shall gant that a good Lisp function can
ing" in India. More efficient woodbuming probably opt for the Chinese viewpoint. please a Lisper as a poempleases a lover
stoves for the Sahel. Photovoltaic irrigation And if I find out that the SEARLE sys- of poetry. My colleague Dan Friedman
pumps for the Somali refugee camps. tem is in turn implemented on top of a
All these are solutions to technical prob- is in fact compiling a book titled Lisp
lems in developing countries. Devising Lisp system, then I have yet a third point Poems, and he urges interested readers
such solutions is no simple task. To apply of view to choose. And so on. to send him their most elegant efforts.
the most advanced results of modern sci- With interpreters stacked on inter- His address is Computer Science De-
ence to the problems of developing areas preters, however, things rapidly become partment, Indiana University, Bloom-
in a form that can be adoptedby the people very inefficient. It is likerunning a motor ington, Ind. 47405.
requires the skills of the best scientists, on power coming from a series of elec- What properties of Lisp, then, have
engineers, —
businessmen people tric generators,each generatorbeing run made it central to AI research? I would
whose jobs may involve creating solid state on power coming from the preceding say the following ones are nearly ex-
systems or farming 1000 acres, but who one: a good dealof poweris lost at each
can also design a solar still appropriate to haustive:
Mauritania or an acacia-fueled methane stage. With generators there is usually 1. Lisp is crisp.
digester for Nicaragua. no need for a long cascade, but with in- 2. Lisp is interactive.
Such are the professionals who volun- terpreters it is often the only way to go. 3. Lisp is centered on the idea of lists
teer their spare time to Volunteers in Tech- If there is no machine whose machine and their manipulation, and lists are ex-
nical Assistance (VITA), a 20 year old pri- language is Lisp, then you build a Lisp tremely fluid data structures.
vate, non-profit organization dedicated to interpreter for whatever machine you 4. Lisp code, having the same form as
helping solve development problems for have available and run Lisp that way. Lisp data, can easily be manufactured in
people world-wide. And Flumsy or if you want to Lisp and run.
Four thousand VITA Volunteers from 82 have it at your disposal, is then built on
countries donate their expertise and time 5. Interpreters for new languages can
to respond to the over 2500 inquiries re- top of this "virtualLisp machine."Such easily be built and experimented with
ceived annually. Volunteers also review indirectness can be annoyingly ineffi- in Lisp.
technical documents, assist in writing VITA's cient, causing your new virtual Flumsy 6. "Swimming"in a Lisplike environ-
publications and bulletins, serve:on tech- machineor virtual SEARLE machine to ment feels natural for many people.
nical panels, and undertake short-term run dozens of times slower than you 7. Lisp is permeated by the "recursive
consultancies. would like. spirit."
Past volunteer responses have resulted There have been important hardware Perhaps it is this last rather intangible
in new designs for solar hot water heaters developments in the past several years,
and grain dryers, low-cost housing, the
statement that gets at it the best. For
windmill shown above and many others. and nowmachines are available that are some reason, many people in artificial
Join us in the challenge of developing even based on Lisp at the hardware level. intelligence seem to have a deep sense
more innovativetechnologiesfor the future. This means that they "speak" Lisp in that recursivity, in some form or other,

a somewhat deeper sense let us say is connected with the "trick" of intel-
yfvA Putting Resources "more fluently"—than virtual Lisp ma-
chines. It also means that when you are
ligence. It is a hunch, an intuition, a
vaguely, felt and slightly mystical be-
to Work for People working on such a machine, you are
3706 Rhode Island Aye, Mt. Maryland 20712
and one that I certainly share, but
"swimming" in a Lisp environment. A whether it will pay off in the long run
Lisp environment goes considerably be- remains to be seen.
28

You might also like