WRITING
PROGRAM
by Philip Elmer-DeWitt
Philip Elmer-DeWitt writes the Computers column for Time magazine. His wife has yet to use his Apple II.
Affairs of the heart, we are assured, will always be what make you and me different from computers. (I trust this is being read by a fellow human and not some computerized optical character reader.) Computers will never feel emotions like love, tenderness and devotion. With all the artificial intelligence in the world, machines will never have what it takes to write an Anna Karenina or even a successful Harlequin romance. Or so we are told.
And yet computers are already duplicating certain kinds of human intercourse. "Personalized" junk mail, for instance, pretends to a kind of intimacy by liberally sprinkling your name throughout its text as it cajoles you to sign up and buy something or other. This is a relatively simple form of computerized text manipulation, in which addresses and names from an electronic master list are substituted at key places in a document.
Other products of list manipulation, among them synthesized poetry, form the core of much of the research in the artificial intelligence community. In fact, the computer language most favored in this sector is LISP (short for List Processing language). A simplified version of this language is available in Logo, a subset of LISP's powerful set of instructions.
Curious about how emotional a computer could get, I sat down one day with an Apple II Plus and a copy of Logo, and wrote the little program called Loveletter. Known in the trade as a "toy" program, so trivial as to seem almost pointless, Loveletter writes little billets-doux suitable for pinning to a pillowcase. With more programming it could be taught to vary the structure of its letters, but that improvement would have made it too long to reprint here.
Given a few appropriate lines of text, Loveletter will generate notes like the following:
DEAR MARY
SINCE THAT NIGHT IN BARBADOS
MY LIFE SEEMS RICHER AND RICHER
YOU ARE S00000 SEXY
I WANT YOU RIGHT NOW
SAY YES AND YOU WILL NEVER BE SORRY
PHILIP
DEAR MARY
SINCE I SAW YOU LAST
MY LIFE JUST GETS BETTER AND BETTER
YOU ARE GETTING STRONGER BY THE MINUTE
I WANT ALL OF YOU
SAY YES AND YOU'LL NEVER SAY NO
PHILIP
Loveletter is printed in its entirety on the next page. With Apple Logo, you start the program by telling the computer to GETREADY, then type LOVELETTER. (The program also runs as written on M.I.T. Logo or Digital Research's DR Logo. Other versions, notably Texas Instruments', require modifications.)
This program consists of one main procedure and three attendant subprocedures. Procedures are what Logo is all about. The language comes equipped with a standard set, which you combine to make new procedures. These, in turn, can be combined in new and more complex procedures, and so on indefinitely. Procedures send messages to and from each other via inputs and outputs. The procedure PICKRANDOM, for example, inputs a list and outputs an item picked at random from that list.
Look at the main procedure, LOVELETTER. If you type LOVELETTER and hit RETURN, the Logo interpreter will start processing these capitalized words one line at a time. The word TO in the first line alerts Logo that what follows is a definition. The last line, END, indicates that the definition is complete. The lines in between are the actual instructions. Each time Logo is told to LOVELETTER, it gets itself a copy of this definition and starts executing the instructions one line at a time.
Now look at the first line in LOVELETTER:
PRINT SENTENCE [DEAR] PICKRANDOM :LOVER
Notice that there are no prepositions (of, by) in the Logo language. Also notice the strange punctuation. All this is significant. The brackets ([ ... ]) and colon (:) are used in Logo to differentiate between things and the names of things. PRINT and SENTENCE are built-in procedures: SENTENCE takes two words or phrases and puts them together with a blank space in between; PRINT displays words on a TV screen or printer. Reading from left to right, Logo understands this line to say: print on the TV screen a sentence made up of the word DEAR and a word chosen randomly from a list of words called LOVER. When instructed to LOVELETTER, the first thing Logo will do is type:
DEAR MARY
The next six lines of the LOVELETTER procedure work in much the same way. Basically, they construct sentences by tacking nouns and verbs (YOU ARE . . . ; I WANT ... ) onto randomly chosen memories, desires, promises. At first the program's data base contains only those memories supplied by the start-up procedure GETREADY. But the lists of names and phrases soon grows longer, thanks to the procedure called LEARNANOTHER invoked toward the end of Loveletter. LEARNANOTHER simply asks the user to "teach it" another phrase and then adds that new phrase onto the end of the original list.
The last instruction of Loveletter is to LOVELETTER again. This sends the program back to its own beginning. The endless loop this creates is a simple example of recursion, a powerful programming tool useful in moving through treelike data base structures and one of the features that distinguishes modern high-level languages like Logo, LISP, Pascal and FORTH from more primitive languages like COBOL, FORTRANand BASIC. (Most video games are written in the even more primitive "assembly" languages.) BASIC and FORTRAN were designed to solve formulas by manipulating numbers. Logo, from the Greek for "word," was designed to manipulate words, sentences and lists.
It took me less than half an hour to write a crude version of Loveletter, another thirty minutes to debug and polish it off, and about three minutes to exhaust my interest in playing with it. But before the program got boring, something interesting happened: like the inkblots in a Rorschach test, the letters it generated started to reflect my unconscious preoccupations. The deeper I dredged my mind for MEMORYs and DESIRES, the racier my loveletters got. Before long they were unprintable. My wife wandered by at one point and looked briefly over my shoulder. "You're very weird" was all she had to say.
To LOVELETTER PRINT SENTENCE [DEAR] PICKRANDOM :LOVER PRINT SENTENCE [SINCE] PICKRANDOM :MEMORY PRINT SENTENCE [MY LIFE] PICKRANDOM :HOWCHANGED PRINT SENTENCE [YOU ARE] PICKRANDOM :NICETHING PRINT SENTENCE [I WANT] PICKRANDOM :DESIRE PRINT SENTENCE [SAY YES AND] PICKRANDOM :PROMISE PRINT PICKRANDOM :SIGNOFF PRINT SPACE LEARNANOTHER PICKRANDOM[LOVER MEMORY HOWCHANGED NICETHING DESIRE PROMISE SIGNOFF] LOVELETTER END TO:GETREADY MAKE "LOVER [[MARY]] MAKE "MEMORY [[WE MET AT JESSICA'S PARTY THAT SECOND TIME AROUND]] MAKE "HOWCHANGED [[HAS BEEN INFUSED WITH A DAWNING SENSE OF UNBELIEVABLE GOOD LUCK]] MAKE "NICETHING [[THE BEST]] MAKE "DESIRE [[TO MARRY YOU]] MAKE "PROMISE [[I'LL SPEND MY LIFE MAKING YOU HAPPY]] MAKE "SIGNOFF [[PHILIP]] MAKE "SPACE [] END TO LEARNANOTHER CATEGORY PRINT SENTENCE [TEACH ME ANOTHER]:CATAGORY MAKE :CATEGORY SENTENCE (THING :CATAGORY)(LIST READLIST) PRINT :SPACE END TO PICKRANDOM :LIST OUTPUT (ITEM (1 + rANDOM (COUNT :LIST)) :LIST END ?LOVELETTER DEAR MARY SINCE WE MET AT JESSICA'S PARTY THAT SECOND TIME AROUND MY LIFE HAS BEEN INFUSED WITH A DAWNING SENSE OF UNBELIEVABLE GOOD LUCK YOU ARE THE BEST I WANT TO MARRY YOU SAY YES AND I'LL SPEND MY LIFE MAKING YOU HAPPY PHILIP TEACH ME ANOTHER HOWCHANGED |
Return to Table of Contents | Previous Article | Next Article