L10 W65 
UThe Logo NotebookU 
 
by R.H. Mitchell 
 
This is the second in a series of articles about LOGO. The information presented is not intended to replace a thorough reading of the SmartLOGO instruction manual, but rather to serve as a study guide and to provide readers with a different perspective on learning the language. What perspective? Well, we've already become reasonably familiar with SmartBASIC, and now we're trying to unlearn our habits thus far acquired and reprogram ourselves sufficiently enough to permit a look at another way of doing things. 
 
For in fact, learning a computer language involves, to some extent at least, learning different syntaxes for what seem to be similar operations in each language. No matter what the language, there are always routine things that need to be done. 

     - screen control
     - variable assignments 
     - program flow
     - user input
     - output to the screen
     - input/output to disk or datapack
     - output to other peripherals such as the printer
     - mathematical operations
     - logical operations
     - file management
     - memory management
     - control of special resources (like sprites and sound). 
 
From investigations so far, LOGO appears to be a great language for graphics applications. Adamites quite often ask eachother through their newsletters why it isn't used more often and why there aren't more LOGO programs available. Perhaps in our efforts here we can help to answer such questions. 
 
Two things I've heard so far might explain user reluctance to do more in LOGO. The language is slow, and the larger a LOGO program becomes, the more difficult it is to efficiently manage ADAM's memory. I've been hearing about a concept called 'garbage collection' when the latter objection comes up. We'll have to find out exactly what is meant by this term and also to what extent any speed price payable will affect our programming objectives. In any event, it's not likely that either of these two problems will hamper the process of learning the basics. So let's get to it. 
 
Last issue we briefly covered a few screen control commands affecting text and graphics. The two modes of operation, immediate and Edit were discussed. In this article we're going to talk about variables. We'll conclude with a short LOGO program that does not much, but serves to illustrate the things so far addressed. 
 
UVariablesU 
 
Every program you write, except for the most simple, will no doubt involve the use of variables. In SmartBASIC, the statement:

     10 x = 42 
 
reserves memory space for the variable 'x', declares it to be a numeric floating point variable, and assigns it the value 42. The variable 'x$' on the other hand would declare a string variable, and as we all know from experience, trouble follows if we try to mix the two types. In fact in some languages such as C and Pascal, the variable types used are quite extensive and variables must be defined or declared in advance as one of the very first segments of a program. 
 
In LOGO however, there doesn't seem to be any such restriction except for that dictated by good programming practice. You can name a variable anything you like (no LOGO primitives ..please) and assign to it an integer, a floating point number, or a string. LOGO doesn't seem to care. 
 
If you were to load up LOGO and type in the foregoing 'x = 42' statement, you would be informed:

  I DON'T KNOW HOW TO X 
 
When you're in LOGO, there's one very basic thing you have to remember. The interpreter belives that every word you type in is the name of a PROCEDURE unless you tell it otherwise. So let's try something else.

  MAKE "X 42 
 
With this you'll find that LOGO stops complaining, and waits with its '?' prompt for your next entry. 
 
Now, suppose we want to find the value of our variable X. Here's how we do it.

  PR :X 
 
And LOGO will respond:

  42 
 
Note that the first time we referred to our variable we used an open quote to tell LOGO we were talking about the LITERAL X and not a PROCEDURE called X. What's with the semicolon? The semicolon before a name is used to denote a VARIABLE. So by using ':X', we now tell LOGO we're talking about a VARIABLE X. Clear as mud? 
 
You can make :X just about anything you want.

  MAKE "X 42 
 
or
  MAKE "X "ADAM 
 
or
  MAKE "X 27.90375 
 
or

  MAKE "X [LEFT HANDED SKYHOOKS] 
 
Note the last example assigns a list to X and a list is always enclosed in squarebrackets. 
 
There's another LOGO primitive that can be used to make variable assignments: the command NAME

  NAME [RIGHT HANDED SKYHOOKS] "X

  NAME 27.90375 "X

  
 
Both commands do exactly the same thing, and the order of inputs is reversed. The advantage of one over the other is not yet apparent, but will no doubt surface in due course. 
 
Any variables assigned with the commands MAKE or NAME are global. That is they exist in the workspace for all procedures, and all procedures can make use of them. 
 
Another means of assigning variables produces what are called LOCAL variables, that is variables that are known only within a particular procedure. If you examine the procedure SQUARE in the program which follows, you'll see that along with it's name on the same line there is also a parameter ':COLOR'. This parameter is called an 'INPUT'. As it's being called, the procedure SQUARE is given an input :COLOR, which is itself a variable, to work with. In fact the procedure will not run unless a value for :COLOR is provided...and you'll get

    NOT ENOUGH INPUTS TO SQUARE 
 
So these are the three LOGO ways of declaring variables and assigning values to them . You'll also find that you can edit the values of all variables in your workspace by using the command EDNS. EDNS puts you into the edit mode, prints out all the variable names you've used and gives you their currently assigned values. You can then change any or all of these values and run your procedure(s) again. 
 
Oh yes, and one more thing. What happens when you try to print the value of a variable without first having assigned one? If we were to type in:

   PR :RON 
 
LOGO would sarcastically proclaim:

   RON HAS NO VALUE 
 
Thanks a lot!!! 
 
UA short DEMOU 
 
Type in the following program and save it to your media by entering

  SAVE "DEMO.LGO 
 
Then simply type PROGRAM

  Here's a short explanation. The main loop is the procedure PROGRAM which calls all of the other sub-procedures. START clears the screen, draws a coloured box at the top and fills it with another colour. TITLE positions the cursor in the coloured box and prints two introductory lines of text. DRAWSQUARES assigns a colour number to each of two boxes to appear below the title box and then produces these squares by calling its sub-procedure SQUARE :COLOR. The procedure PRTVRBLS assigns values to the variables :X and :Y, sets the cursor at an appropriate point within each box and then prints the values of the variables. Finally, FINISH cleans things up by changing the background and print colours. It then moves the cursor to the bottom of the screen where it will be out of the way. 
 
Next time we'll look at the various colour commands illustrated here and work on our demo a little more. 
 short DEMOU 
 
Type in the following program and save it to your media by entering

  SAVE "DEMO.LGO 
 
Then simply type PRO
