Logo Programming Basics
Messages from Foo
Download this worksheet and fill it out as you watch the videos below. The worksheet will be used in class discussions and as preparation for the upcoming quiz.
You should also try out some of the code you see and experiment with your own.
MicroWorlds Episode 1: Introducing Foo
MicroWorlds Episode 2: Foo's language
MicroWorlds Episode 2 Redux: What was that again?
MicroWorlds Episode 3: Words in Logo as understood by Foo
MicroWorlds Episode 4: Why doesn't this command like that word as input?
MicroWorlds Episode 5: Lists
The material in the next section covers concepts that will help you think more clearly about how Logo works. The definitions are shown in the tabbed section below. For more detail, see Definitions or Readings and Problems.
An instruction is a command together with the inputs it needs to do its work. For example, the line below contains two instructions:
fd 5 wait 1
A group of instructions that do a particular job is called a procedure. You can write your own procedures or use procedures called primitives that come with MicroWorlds.
Commands are procedures that are used to change the state of projects, pages, turtles, buttons, sliders, text boxes, colors, hyperlinks, media objects, dialog boxes, choosers and the Command Center.
Commands don't report output to other proceduresExamples of commands: presentationmode, page1, setx, fd, setslider1, set. The following procedures are not commands: xcor, sum, word, get.
A procedure that reports output to other procedures is called a reporter. The OP command is used to report output from procedures that you write yourself.
Examples of reporters: color, quotient, first, text1, get. The following procedures are not reporters: freezebg, page1, setc, fd, settext1, set.
Input is the information a procedure needs before it can be invoked. For example, in the following instruction
50 is the input to the fd command
Output is the information reported by a reporter. For example, in the instruction below
fd product 5 10
the output of the product reporter is 50.
A word is a collection of characters. The simplest way to get Foo to evaluate something as a word is to put quotation marks in front of it. Foo also recognizes numbers as words. Here are some words:
"hello 25 "|a word with spaces| "@.#%
Notice that an opening and closing bar (|) is used to make a word that contains spaces. Reporters may report words, but they may also report lists. Commands never report words or anything else.
A list is a collection of words. Brackets are used to show the beginning and end of a word. Here is a list:
[How are you?]
A list can be a member of a list.
[[chocolate fudge] vanilla [cherry garcia]]
The list above has three members. The first and third members are lists, and the second member is a word.
An instruction is evaluated when Foo reads it and decides whether to invoke a procedure, look for more input, or send back an error message. For example, suppose your project page has a text box called text1 and text1 has a 7 in it. You send the following message to Foo:
settext1 sum text1 1
Foo first evaluates
and next evaluates
sum 7 1
A procedure is invoked when it is made to do it work. Procedures are invoked in a particular order. For example, suppose you sent the following message to Foo:
show butfirst [show rest of words]
The first thing Foo sees is show, but he can't invoke show until he gets input for it, so the first procedure to be invoked is butfirst:
butfirst [show rest of words]
now Foo can invoke show:
show [rest of words]