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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
|
<HTML>
<HEAD>
<TITLE>Computer Science Logo Style vol 1 ch 1: Exploration</TITLE>
</HEAD>
<BODY>
<CITE>Computer Science Logo Style</CITE> volume 1:
<CITE>Symbolic Computing</CITE> 2/e Copyright (C) 1997 MIT
<H1>Exploration</H1>
<TABLE width="100%"><TR><TD>
<IMG SRC="../csls1.jpg" ALT="cover photo">
<TD><TABLE>
<TR><TD align="right"><CITE><A HREF="http://www.cs.berkeley.edu/~bh/">Brian
Harvey</A><BR>University of California, Berkeley</CITE>
<TR><TD align="right"><BR>
<TR><TD align="right"><A HREF="../pdf/v1ch01.pdf">Download PDF version</A>
<TR><TD align="right"><A HREF="../v1-toc2.html">Back to Table of Contents</A>
<TR><TD align="right"><A HREF="../v1ch0/ack.html"><STRONG>BACK</STRONG></A>
chapter thread <A HREF="https://people.eecs.berkeley.edu/~bh/v1ch2/v1ch2.html"><STRONG>NEXT</STRONG></A>
<TR><TD align="right"><A HREF="https://mitpress.mit.edu/books/computer-science-logo-style-second-edition-volume-1">MIT
Press web page for Computer Science Logo Style</A>
</TABLE></TABLE>
<HR>
<P>The name Logo comes from the Greek word <EM>logos,</EM> which means
"word." In contrast to earlier programming languages, which
emphasized arithmetic computation, Logo was designed to manipulate
language--words and sentences.
<P>Like any programming language, Logo is a general-purpose tool that
can be approached in many ways. Logo programming can be understood
at different levels of sophistication. It has been taught to
four-year-olds and to college students. Most of the books about
Logo so far have been introductory books for young beginners, but <EM>
this</EM> book is different. It's for somewhat older learners,
probably with some prior computer experience, although not
necessarily Logo experience.
<P>This book was written using the Berkeley Logo dialect, a version
of Logo that's available at no cost for PCs, Macintoshes, and Unix
systems. Recent commercial Logo
dialects have emphasized the control of real-time animation,
robotics, and other such application areas, somewhat at the
expense of more traditional Logo features designed to be useful
in the development of larger and more complex programs. Berkeley
Logo follows the traditional design, so you may miss some
"bells and whistles" that you associate with Logo from
elementary school. In fact, we'll hardly do any graphics
in this book!
<P>Some of the details you'll have to know in order to work with Logo
depend on the particular kind of computer you're using. This
book assumes you already know some things about your computer:
<UL>
<LI> How to turn on your computer and start Logo
<LI> How to type a command, ending with the RETURN key
<LI> How to use control keys to correct typing mistakes
<LI> How to use a text editing program
</UL>
<P>
These points I've listed aren't actually part of the Logo
<EM>language</EM> itself, but they're part of the Logo programming
<EM>environment.</EM> Appendix A has a brief guide to some of these
machine-specific aspects, but if you've never used a computer before
at all, start by working with some application programs
to get the feel of the machine.
<P>On the other hand, I'd like to pretend that you know nothing about
the Logo language--the primitive procedures, the process of
procedure definition, and so on--even if you've really used Logo
in elementary school. The reason for this pretense is
that I want you to think about programming in what will probably be
a new way. The <EM>programs</EM> may not be new to you, but the <EM>
vocabulary</EM> with which you think about them will be. I'm warning
you about this ahead of time because I don't want you to skip over
the early chapters, thinking that you already know what's in them.
<P>Okay, it's time to start Logo running on your computer. You should
then see a screen that says something like
<P><PRE>Welcome to Berkeley Logo version 3.3
?
</PRE>
<P>The question mark is Logo's <EM>prompt.</EM> When you
see the question mark, it means that the computer is prepared for you
to type in a Logo <EM>instruction</EM> and that Logo will carry
out the instruction as soon as you finish it.
<P>
<H2>Getting Acquainted with Logo...</H2>
<P>Right now, type this instruction:
<P><PRE>repeat 50 [setcursor list random 75 random 20 type "Hi]
</PRE>
<P>Remember that square brackets <CODE>[]</CODE> are different from
parentheses <CODE>()</CODE>. Also remember that it's important to put
spaces between words. However, it doesn't matter whether you use
<CODE>UPPER CASE</CODE> or <CODE>lower case</CODE> letters in the words that Logo understands.
<P>If all goes well, Logo will cheerfully greet you by scattering <CODE>
Hi</CODE>s all over the screen. If all doesn't go well, you probably
misspelled something. Take a look at what you typed, and try again.
<P>Afterward, you can clear the screen by typing <CODE>cleartext</CODE> or
its abbreviation <CODE>ct</CODE>.
<P>
<H2>... in Two Senses</H2>
<P>I thought it would be appropriate to start exploring Logo by having
it say hello. You and Logo can get acquainted as you would with
another person.
<P>But, of course, the point of the exercise is to get acquainted with
Logo in a more serious sense too. You're seeing what a Logo
instruction looks like and a little bit about what kinds of things
Logo can do. In this first chapter the kind of acquaintance I have
in mind is relatively superficial. I'm trying to get across a broad
sense of Logo's flavor rather than a lot of details. So I'm not
explaining completely what we're doing here. For that reason, the
second chapter will repeat some of the same activities, but I'll
give a more detailed discussion there.
<P>Perhaps you've made Logo's acquaintance before, probably through the
medium of turtle graphics. In that first introduction you may have
explored Logo's ability to manipulate text as well as graphics. But
maybe not. Writing a book like this, it's not easy for me to carry
on a conversation with someone I haven't met, so in this
introduction I may be saying too much or too little for your
individual situation. I hope that by the second chapter you and the
other readers will all be ready for the same discussion.
<P>If you haven't used Logo before, or if you've used only the part of
Logo that has to do with turtles, look at the instruction I asked
you to type earlier. Think about the different parts of that
instruction, the words like <CODE>repeat</CODE> and <CODE>random</CODE> and <CODE>
setcursor</CODE>. Try to figure out what each one means. Then see
if you can figure out an experiment to decide if you've understood
each word correctly! Later, we'll go over all these details and
you'll learn the "official" explanations. But the kind of
experimenting I'm suggesting isn't pointless. This kind of
exploration may raise questions in your mind, not just about the
meanings of the Logo words but about how they're connected together
in an instruction, or about <EM>why</EM> a word means just what it
does rather than something a little different.
<P><H2>Another Greeting</H2>
<P>Here is a somewhat less "scatterbrained" greeting instruction:
<P><PRE>repeat 20 [repeat random 30 [type "Hi] print []]
</PRE>
<P>Try that one. Compare it to the one we started with.
Which do you like better? Do you prefer random scattering, or
orderly rows? Perhaps this question will teach you something about
your own personality!
<P><H2>Fooling Around</H2>
<P>Then again, maybe you think this is all silly. If so, I'd like to
try to convince you that there are some good, serious reasons for
you to take a lighthearted approach to computer programming, no
matter how serious your ultimate goals may be.
<P>There are two aspects to learning how to program in a language like
Logo. One aspect is memorizing the vocabulary, just as in learning
to speak French. If you flip through the reference manual that came
with your Logo,<SUP>*</SUP> you'll find that it's a sort of dictionary,
translating each Logo word into a bunch of English words that
explain it. But the second aspect is to learn the "feel" of
Logo. What kinds of problems does Logo handle particularly well?
What are the examples of programming <EM>style</EM> that correspond
to the idioms of a human language? What do you do when something
doesn't work?
<P><SMALL><BLOCKQUOTE><SMALL><SUP>*</SUP>If you're using Berkeley Logo, it's in a file
named <CODE>usermanual</CODE> (or <CODE>userman.ual</CODE> if you're
using a DOS machine) that should be installed along with the Logo
program. The Berkeley Logo reference manual is also an appendix
to Volume 2 of this series.</SMALL></BLOCKQUOTE></SMALL><P>It is by fooling around with Logo that you learn this second aspect
of the language. Starting with the second chapter of this book,
we'll be going through plenty of dry, carefully analyzed fine points
of Logo usage. But as we progress, you should still be fooling
around, on the computer, with the ideas in the chapters.
<P>In fact, I think that that kind of intellectual play is the best
reason for learning about computer programming in the first place.
This is true whether you are a kid programming for the fun of it or
an adult looking for a career change. The most successful computer
programmers aren't the ones who approach programming as a task they
have to carry out in order to get their paychecks. They're the ones
for whom programming is a joyful game. Just as a baseball diamond
is a good medium in which you can exercise your body, the computer
is a good medium in which you can exercise your mind. That's the
real virtue of the computer in education, not anything about job
training or about arithmetic drill.
<P><H2>A Slightly Longer Conversation</H2>
<P>The Logo words such as <CODE>print</CODE> and <CODE>random</CODE> are the names of
<EM>procedures,</EM> little pieces of computer program that are
"specialists" in some particular task. We are now going to add to
Logo's repertoire by inventing a new procedure named <CODE>hi</CODE>.
At the question mark prompt, start by typing this:
<P><PRE>to hi
</PRE>
<P>The word <CODE>to</CODE> here is short for "here's how to." The
name is intended to suggest the <EM>metaphor</EM> that what
you're doing when you write computer programs is to <EM>teach</EM>
the computer a new skill. Metaphors like this can be very helpful
to you in understanding a new idea. (Just ask any English
teacher.) I'll point out other metaphors from time to time.
<P>Logo should have responded to this instruction by printing a
different prompt character. Instead of the question mark,
you should now see a greater-than sign (<CODE>></CODE>) at the beginning
of the line:
<P><PRE>? <U>to hi</U>
>
</PRE>
<P>(Whenever I show an interaction with the computer in this
book, I'll show the part that you're supposed to type <CODE>
<U>underlined</U></CODE>; what the computer prints in response is <CODE>not
underlined</CODE>.
But I won't underline when I'm only showing what you type and
not a complete interaction.) This new prompt means that Logo will
not immediately carry out whatever instructions you type; instead
Logo will remember these instructions as part of the new procedure
<CODE>hi</CODE>. Continue typing these lines:
<P><PRE>print [Hi. What's your name?]
print sentence [How are you,] word first readlist "?
ignore readlist
print [That's nice.]
end
</PRE>
<P>Again, be careful about the spaces and punctuation. After
the last line, the one that just says <CODE>end</CODE>, Logo should go back
to the question mark prompt. Now just type
<P><PRE>hi
</PRE>
<P>on a line by itself. You can carry on a short
conversation with this program. Here's what happened when I tried
it.
<P><PRE>? <U>hi</U>
Hi. What's your name?
<U>Brian Harvey</U>
How are you, Brian?
<U>I'm fine.</U>
That's nice.
</PRE>
<P>If something unexpected happens when you try it, perhaps
you made a typing mistake. If you know how, you can fix such
mistakes using the Logo editor. If not, you'll have a chance to
review that process later, but for now, just start over again but
give the procedure a different name. For example, you can say
<P><PRE>to hi2
</PRE>
<P>for the second version of <CODE>hi</CODE>.
<P>»This program pretends to be pretty smart. It carries on a
conversation with you in English. But of course it isn't really
smart. If you say "I feel terrible" instead of "I'm fine," the
procedure cheerfully replies "That's nice" anyway. How else can
you mess up the program? What programming tools would you need to
be able to overcome the "bugs" in this program?
<P>(When a paragraph starts with this symbol » it means that
the paragraph asks you to invent something. Often it will be a Logo
program, but sometimes, as in this case, just answers to questions. This is
a good opportunity to take a break from reading, and check on your
understanding of what you've read.)
<P><H2>A Sneaky Greeting</H2>
<P>This chapter started as a sort of pun in my mind--the one about
getting acquainted. How should I have Logo introduce itself? I'm
still playing with that idea. Here's another version.
<P><PRE>to start
cleartext
print [Welcome to Berkeley Logo version 3.3]
type "|? |
process readlist
type "|? |
wait 100
print [Ha, ha, fooled you!!]
end
to process :instruction
test emptyp :instruction
iftrue [type "|? | process readlist stop]
iffalse [print sentence [|I don't know how to|] first :instruction]
end
</PRE>
<P>The vertical bars are used to tell Logo that you want to
include space characters within a word. (Ordinarily Logo pays no
attention to extra spaces between words.) This is the sort of
grubby detail you may not want to bother with right now, but if you
are a practical joker you may find it worth the effort.
<P><H2>A Quiz Program</H2>
<P>Before we get on to the next chapter, I'll just show you one more
little program. Try typing this in. As before, you'll see
greater-than prompts instead of question marks while you're doing
it.
<P>
<PRE>to music.quiz
print [Who is the greatest musician of all time?]
if equalp readlist [John Lennon] [print [That's right!] stop]
print [No, silly, it's John Lennon.]
end
</PRE>
<P>You can try out this procedure by typing its name as an
instruction.<SUP>*</SUP>
<P><SMALL><BLOCKQUOTE><SMALL><SUP>*</SUP>It has been suggested by some reviewers of the
manuscript that there may be younger readers who don't know who John Lennon
is. Well, he's the father of Julian Lennon, an obscure rock star of the
'80s, and he used to be in a rock group called the Quarrymen. If you have
trouble with some of the cultural references later in the book you'll have
to research them yourself.</SMALL></BLOCKQUOTE></SMALL><P>»If you don't like my question, you could make up your own procedures
that ask different questions. Let's say you make up one called <CODE>
sports.quiz</CODE> and another called <CODE>history.quiz</CODE>, each asking and
answering one question. You could then put them all together into one
big quiz like this:
<P><PRE>to total.quiz
music.quiz
sports.quiz
history.quiz
end
</PRE>
<P><H2>Saving Your Work</H2>
<P>If you do write a collection of quiz procedures, you'll want to save
them so that they'll still be available the next time you use Logo.
Certainly you'll want to save the work you do in later chapters.
You can ask Logo to record all of the definitions you've made as
a <EM>workspace</EM> file using the <CODE>save</CODE> command. For example,
if you enter the instruction
<P><PRE>save "mystuff
</PRE>
<P>you are asking Logo to write a disk file called <CODE>mystuff</CODE>
containing everything you've defined. (The next time you use Logo, you can
get back your definitions with the <CODE>load</CODE> command.)
<P>Don't get confused about the difference between a <EM>procedure</EM> name
and a <EM>workspace</EM> name. Logo beginners sometimes think that <CODE>
save</CODE> saves only a single procedure, the one whose name you tell it (in this
example, a procedure named <CODE>mystuff</CODE>). But the workspace file named
<CODE>mystuff</CODE> will actually contain <EM>all</EM> the procedures you've defined.
In fact, you probably don't have a procedure named <CODE>mystuff</CODE>.
<P>The format for the name of a disk file will depend on the kind of computer
you're using, whether you're writing to a hard disk or a floppy disk, and so
on. Just use whatever file name format your system requires in other
programs, preceded by the quotation mark that tells Logo you're providing
a word as the input to the <CODE>save</CODE> command.
<P><H2>About Chapter 2</H2>
<P>In this chapter the emphasis has been on <EM>doing</EM> things. You've
been playing around with some fairly intricate Logo instructions,
and if you don't understand everything about the examples, don't
let that worry you.
<P>Chapter 2 has the opposite emphasis. There is very little to do,
and the examples will seem quite simple, perhaps even insultingly
simple! But the focus of the chapter is on <EM>understanding</EM> those
simple examples in great detail.
<P>Logo deserves its reputation as an easy-to-learn language, but it
is also a very sophisticated one. The ease with which Logo can be
learned has lured many people into sloppy thinking habits that make
it hard for them to grow beyond the most trivial programming. By
studying examples that seem easy on the surface, we can start exploring
<EM>below</EM> the surface. The important questions will not be ones
like "what does <CODE>print</CODE> do," but instead ones like "what is going
on <EM>inside</EM> the Logo interpreter when I type <CODE>print</CODE>?"
<P>Later chapters will strike more of a balance between things to do
and things to think about. If the pace seems slow in chapter 2, glance
back at the table of contents to reassure yourself about how much
territory we'll cover before the end of the book. Then keep in mind
that you'll need the ideas from chapter 2 in order to understand what
comes later.
<P><H2>No Exercises</H2>
<P>This is the point in the chapter where you might be expecting a set
of exercises: Problem 1.1, get the computer to print your name.
<P>There aren't any exercises--but not because you shouldn't try using
Logo at this point. The reason is that part of the challenge is for
<EM>you</EM> to invent things to try, not just rely on me for your ideas.
In each chapter there will be some sample procedures to illustrate
the new information in the chapter. You should try to invent programs
that use those ideas.
<P>But I hope it's clear by now that I don't want you to do this with
a sense of duty. You should play with the ideas in each chapter only
to the extent that it's interesting and mind-stretching for you to
do so.
<P>In this chapter I really haven't yet told you any of the rules for
putting together Logo instructions. (I'll do that in Chapter 2.)
So you shouldn't get discouraged or feel stupid if you don't get very
far, right now, in playing with Logo. It will be a few more chapters
before you should expect to feel really <EM>confident</EM> about undertaking
new projects of your own. But you won't break anything by trying
now. Go ahead, fool around!
<P><A HREF="../v1-toc2.html">(back to Table of Contents)</A>
<P><A HREF="../v1ch0/ack.html"><STRONG>BACK</STRONG></A>
chapter thread <A HREF="https://people.eecs.berkeley.edu/~bh/v1ch2/v1ch2.html"><STRONG>NEXT</STRONG></A>
<P>
<ADDRESS>
<A HREF="../index.html">Brian Harvey</A>,
<CODE>bh@cs.berkeley.edu</CODE>
</ADDRESS>
</BODY>
</HTML>
|