When circumstances allow, I'll be typing up bits of my lecture notes and posting them online. These may or may not bear any resemblance to the actual lectures.Office Hours: Conant 453. Tuesday 11:30-12:30, Wednesday 11-12, Thursday 12:30-1:30 and by appointment.
Other words, like say, draw and arccos are not in Logo's vocabulary. We could add them to Logo's vocabulary by writing procedures with those names.
In order to give instructions to Logo, you need to learn the words it knows. Here are some procedure names you should memorize. Use Logo's help procedure to look up details on using these procdures.
We know that print is a built-in Logo procedure. What happens if we just tell Logo to print? Try it!
Logo tells us not enough inputs to print. It's complaining because we didn't tell it what to print.
Some procedures, like cleartext and readlist, don't need extra information to work. Some procedures, like print and sum, do. An instruction is a statement that contains all the information Logo needs to do something.
Here are some examples of instructions. Try them out!
print [Hello world!] help "readlist print random 7 print sentence "Hello word first readlist forward 30 right 90Here are some examples of things that aren't instructions. Can you guess what's wrong with them?
print print sentence "Hello sum 2 sum 2 3 sentence "Hello "world
Logo told us You don't say what to do with 5. Obviously Logo successfully added 2 to 3. Why is it complaining about the result?
Logo has two types of procedures: commands and operations. Commands such as help, forward, print and save do something for you, like displaying words on the screen. Operations such as sum, readlist, first and list output information for other Logo procedures to use.
In the instruction
print 17the word print is the name of a procedure. The number 17 is input to that procedure. Grammatically, the command print must always be followed by what you want Logo to print. (What happens if you just type print at the ? prompt and hit enter?)
The textbook tells us more about the grammatical rules for communicating with Logo:
A complete instruction is a command followed by as many expressions as it needs.
A "complete instruction" is a sort of Logo sentence telling Logo to perform one task. Examples of complete instructions include:
cleartext print 17 repeat 50 [setcursor list random 75 random 20 type "Hi]
The number of expressions a procedure needs in order to operate depends on the procedure -- expressions (or "inputs") like 17 and [forward 100 right 90] are sometimes required to describe what the procedure is supposed to do.
To find out what type and how many inputs a procedure requires, type help followed by quotes and the procedure name at the question mark prompt. For example, help "repeat, help "print or help "textscreen. (Procedure help is a command which requires one input -- the name of a procedure.)
Another example of a complete instruction is:
print sum 12 5Here sum 12 5 is the expression that tells print what to display. The input to print is the "output" given to it by procedure sum.
Procedure sum is an operation -- a procedures that outputs information for other procedures. To complete the instruction sum 2 3 we might choose print sum 2 3. As another example,
forward random 150draws a random length line on the screen. The instruction:
random 150generates an error message like: You don't say what to do with 33.
In the first example, random 150 is doing something for procedure forward and forward is doing something for you -- showing you a line segment with a random length. In the second example random 150 tries to do something for a procedure, but there is no procedure for it to help.
The book explains the difference between these two types of procedure on page 17:
An operation is a procedure that computes a value and outputs it; random, list and readword are operations.
A command is a procedure that does not output a value but instead has some effect, such as displaying something on the screen; print, save, left and forward are commands.
We will see many examples of commands and operations in this class, and will often see error messages when we accidentally treat operations as if they were commands. A common mistake on homework is to write procedures that are commands when you're asked to write operations. As long as you test everything carefully to be sure it does what you think it does, you should be able to stay out of trouble.
What do you think the instruction print sum 4 product 10 2 will do when entered in Logo? Try it!
On page 14 in Chapter 2 the author describes every detail of how Logo parses this instruction. He then recommends a much simpler graphical method of recording the same information called plumbing diagrams. Much of the remainder of chapter 2 involves analyzing commands using plumbing diagrams.
In a plumbing diagram, each procedure is represented by a box. Procedures that require inputs have "hoppers" on top to receive them. Procedures (operations) that produce output have "drain pipes" on the bottom that deposit their output in the hopper of a procedure below. Commands (procedures with no output) do not have drain pipes.
The plumbing diagram for print sum 2 3 would look like:
You can tell that sum 2 3 is not a complete instruction from its plumbing diagram -- the output of the pipe from sum is not collected in a hopper.
You can tell that print sentence "hello is not a complete instruction because one of the hoppers in sentence is unfilled.
The text has an example of the plumbing diaram for print sum 4 product 10 2.
Draw a plumbing diagram for the instruction print sentence "Hello readlist. Use the help command to find out what inputs each procedure requires.
Draw a plumbing diagram for the instruction:
setcursor list random 75 random 20
Draw a plumbing diagram for the instruction:
repeat 50 [setcursor list random 75 random 20]
to welcome print [Welcome to COMP203! What is your name?] print (sentence [I hope you have fun here] word readword "!) endHere the operation readword helps the operation word by outputting whatever is typed at the keyboard when readword is run. Try out the procedure! Here's a simpler procedure using readword:
to testreadword print [Type a word at the keyboard and hit enter.] print last readword print [is the last letter of the word you typed.] end
Type edit "welcome to change procedure welcome, experimenting with word, last, sentence and readword until you know something about what each of these operations does. Use help or ask a neighbor if you get stuck.