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.
Programming languages have as many options for answering this question as we do in real life. Logo's solution is a simple one, though not the simplest.
In the example below (taken from page 50), top is the superprocedure, or boss, and bottom is the subprocedure.
to top :outer :inner print [I'm in top.] print sentence [:outer is] :outer print sentence [:inner is] :inner bottom "x print [I'm in top again.] print sentence [:outer is] :outer print sentence [:inner is] :inner end to bottom :inner print [I'm in bottom.] print sentence [:outer is] :outer print sentence [:inner is] :inner endThis example illustrates the fact that
The most sensible use of global variables is to store values that everybody needs and nobody wants to change. For example, you might store the value of e or pi in a global variable.
In Logo, to avoid accidentally creating global variables we have to specify which procedure a variable belongs to. If you're using functional programming (all variables are procedure inputs) this isn't a problem. However, if you use make to set or change variable values, you should use Logo's local command to prevent creation of extra global variables. Here are some examples to play with:
to makeglobal make "score1 0 print sentence [The value stored in score1 is] :score1 end to makelocal local "score2 make "score2 3 print sentence [The value stored in score2 is] :score2 endRun these procedures, then see what happens when you ask Logo to:
print sentence [The value stored in score1 is] :score1 print sentence [The value stored in score2 is] :score2
Operations provide information to other procedures by outputting data. The logo command output can only be used in a procedure. It requires one input value, and when it's evaluated it ends the procedure it's used in and causes that procedure to output that input value.
to hyphenate :name1 :name2 output (word :name1 "- :name2) endor:
to tan :angle output quotient sin :angle cos :angle end to hypotenuse :leg1 :leg2 output sqrt (:leg1 * :leg1 + :leg2 * :leg2) endWrite a Logo procedure cube which accepts a number as input and outputs the cube of that number.
? print cube 2 8 ? print cube 3 27 ?Notice that because cube is an operation it produces an output which must then be input to print. This is very important! If we want to use our procedures tan or cube in calculations (e.g. of a side length), they must output a value which can be used as input to sum, product, forward, etc. Displaying the value on the screen is no help to forward.
Write down your favorite mathematical function on a piece of paper. Then try to write a logo program which accepts an input and outputs the result of applying that function to the input.
When you've finished, turn to help your neighbor. When both of you have finished, copy each others' functions and use Logo to compose the two functions. You should be able to do this using a command like:
? print function2 function1 7 2.76534619035 ?Can you write a procedure whose output is the derivative of your favorite functin?
Can you and your partner write a procedure to find the derivative of your composition of functions? Recall that: