Learning Logo – Part 2
Background
It’s been a while since I posted Learning Logo – Part One. I’ve resumed Logo lessons with my kids, so I thought I’d post the chapter questions I’ve created for each chapter to accompany Brian Harvey’s excellent texts (see link above for free PDF files for the textbooks).
Chapter One – Exploration
Key Ideas
Chapter one introduces Logo and some of the vocabulary. Simple procedures are written and you learn how to save and load files.
Questions
1) Write a program to print the following: Hello, world! 2) What version of Logo are you using? 3) How many times will hello be printed with the following program? repeat 2 [repeat 2 [repeat 2 [print "hello]]] 4) What is the word to clear the screen? What is its abbreviation? 5) Write a program to print your name 10 times. 6) What does the name Logo come from? 7) Name some Logo procedures. 8) How do you save the workspace to a file named my.logo? 9) How do you load a file named my.logo into the workspace?
Chapter Two – Procedures
Key Ideas
Everything in Logo is done with procedures. Initially, Logo knows about 200 procedures. These are called primitive procedures.
Using the output from one procedure as an input to another procedure is called composition of functions.
In Logo there are two kinds of procedures: commands and operations. An operation is a procedure that computes a value and outputs it. A command is a procedure that does not output a value, but instead has some effect such as printing something on the screen, moving a turtle, or making a sound.
To have Logo treat a word as itself instead of evaluating it, you must quote the word by typing a quotation mark (“) in front of it.
You can combine several words to form a list by using square brackets. For example, [Hello world]. The members of a list can also be lists. For example:
[ [North Carolina] Ohio [South Dakota] ]
The brackets in Logo serve two purposes – they delimit a list and they also quote the list so the members are not evaluated as procedures.
Logo provides several operations for taking data apart and putting data together. Words come apart into characters and lists come apart into whatever data are the members of the list. A sentence, which is a list of words, comes apart into words. For example:
? print first "Hello H ? print first [How are you?] How
Logo provides infix arithmetic as well as prefix arithmetic. For example:
print 2+3 vs. print sum 2 3
Certain primitive procedures can be given extra inputs, or fewer inputs than usual, by using parentheses around the procedure name and all its inputs. For example:
? print sum 2 3 4 5 You don't say what to do with 4 ? print (sum 2 3 4) 9 ? show (list "one) [one] ? show (list) [ ]
Sum, product, word, list, sentence, and print can be used with any number of inputs.
Logo allows creating your own procedures. For example:
to hello print "Hello end
Questions
1) What is the word that describes the special punctuation and organization of a programming language? 2) About how many procedures does Logo know without you teaching it any? What type of procedures are these (e.g. what is a word that describes them)? 3) What is the word that refers to a value that one procedure computes and hands on to another procedure? 4) Using the examples of tanks with inputs and outputs as described on p. 15, draw a picture of the following, then use the picture to determine what will be printed before trying it in Logo: print product sum 1 sum 2 3 sum 4 5 5) What are the two kinds of procedures in Logo? What is the difference between them? 6) Why doesn't the following code work? print Hello 7) Fill in the blanks, "In computer science, to _____ something means to prevent it from being ________." 8) What are four ingredients of a proper description of a procedure? 9) What will the following print? print first first [Hello world] 10) How many inputs does the sentence operation take? 11) What will each of the following instructions print? Think about why. print sentence [one two] [three four] print list [one two] [three four] print item 2 list [one two] [three four] print item 2 sentence [one two] [three four] 12) Use only the following procedures and data (you can use them more than once) to print Logo first butfirst butlast word print [I Love Pogo] 13) How would you write an instruction to print the sum of 1, 2 and 3? 14) What are three reasons parentheses are used in Logo instructions?
Leave a Reply