Part 3 was written with the help of my daughter.
Chapter Three – Variables
Key Ideas
To have a procedure accept input parameters, provide the names of the input parameters preceded by a colon. The colon provides a distinction between the procedure name and input parameters. Some versions of Logo don’t require the colon.
to greet :person
Thing is an operation that takes an input which is the name of a container and outputs the contents of the container.
? to greet :person > print sentence "Hello, thing "person > end greet defined ? greet "Brian Hello, Brian
An abbreviation for thing “person is to simply use a colon.
:person
Sometimes you can even leave the colon off, but you shouldn’t depend on that.
Readlist is an operation that waits for you to type a line, then outputs what you type.
output is a command that has the effect of making its input available as the output of the procedure it’s within.
Logo uses dynamic scope for its variables; however, it’s good style to minimize referencing variables in calling procedures.
make is a command that accepts two inputs. The first input is a word that is the name of a variable; the second input is a value to assign to the variable.
? make "name [Brian Adkins] ? print :name Brian Adkins
The following two lines are equivalent:
make "new :old make first [new old] thing last [new old]
If the first input to make refers to a non-existent variable, a new globabl variable is created. To create a variable local to the procedure, use the local command.
make can use computed names in addition to quoted names. For example, the increment procedure below:
? to increment :variable > make :variable (thing :variable)+1 > end increment defined ? make "foo 7 ? increment "foo ? print :foo 8
A procedure is functional if it always gives the same output when invoked with the same input(s).
Questions
1) Work through all the examples in the chapter to make sure you
understand them.
2) Every variable has a ____ and a _____.
3) Define "formal parameter" and "actual argument"
4) What is another way to say the following?
thing "name
5) Take problem #8 from chapter 1 and solve it without using make to
store a temporary variable. Do you like this solution better or
worse than your solution in chapter 1?
6) A complete instruction begins with which of the following?
operation
command
7) Write the procedure you're asked to write on p. 46 to conjugate
French verbs.
8) Consider the following command:
to thang :thing
print thing :thing
end
How would you invoke this procedure to get it print the following?
thing
9) Write the procedure you're asked to on p. 49:
10) Write the helper procedure you're asked to write on p.54
11) What will the following print?
make "foo 7
make last [foo oof] sum thing first [foo oof] 7
print oof
12) How do you prevent a global variable from being created when using
make with a name that is not the name of an input?
13) What will the following print?
make "a "b
make "b "c
make "c "d
make "d 7
print thing thing thing "a
Tags: logo

1 comment
Comments feed for this article
Trackback link: http://lojic.com/blog/2009/06/28/learning-logo-part-3/trackback/