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.
? converse Please type your full name. Brian Harvey Your first name is: Brian Your last name is: Harvey >
The first attempt at this program usually results in the following behavior:
? converse Please type your full name. Brian Harvey Your first name is: BrianLogo stops halfway through the program! Why?
What happens is that, on the first try, you usually write the following procedure:
to converse print [Please type your full name.] print sentence [Your first name is:] first readlist print sentence [Your last name is:] last readlist endLogo faithfully asks you to type in your name, and readlist faithfully outputs your full name to first, which outputs your first name to sentence, which outputs a sentence to print. (Draw a plumbing diagram if you need help understanding this sentence.) The sentence
Your first name is: Brianappears on the screen. Then Logo tries to run the next instruction. Command print waits for input from operation sentence. Operation sentence has [Your last name is:] as its first input, and the output of last as its second input. Operation last waits for output from readlist. And readlist waits for you to type something at the keyboard. The reason why the program stops is that it's waiting for more input!
Logically, this program makes sense. "Take the first thing in the output of readlist, then take the last thing from that output." However, when you run procedure readlist a second time, it doesn't know what the input was the first time. All it knows is that it's supposed to output something you type at the keyboard.
By now, you may have figured out what we need to do to fix the program. Instead of expecting readlist to remember your name (which it won't), we get Logo to remember your name by storing it in a variable. Then we can use first :variablename and last :variablename to copy the first and last parts of the name stored in the container named variablename.
So far, the only way we know how to store a value in a variable is to make it the input to a procedure. So that's what we'll do:
to converse print [Please type your full name:] halves readlist endNow the output of readlist is the input to some procedure named halves. We don't know what halves looks like yet, but we can already see that it is a command that expects one input, and that that input can be a list.
Procedure halves will store the output of readlist in some variable, and then we can use first and last to look at the value stored in that variable. Problem solved! Try writing procedure halves yourself. If you get stuck, scroll down to see the solution.
to halves :fullname print sentence [Your first name is:] first :fullname print sentence [Your last name is:] last :fullname end
? soap.opera "Bob "Krystal "Susan Krystal had a fight with Bob and Bob and Susan are good friends so now Susan is mad at Krystal. >This is a nice practice problem for working with variables.
? conj "jouer je joue tu joues il joue nous jouons vous jouez elles jouentThis is a very challenging practice problem for working with variables and words. Good luck!