Background
jLogo Programming
- Commanding a Turtle
- Pseudocode
- Adding New Commands
- Iteration & Animation
- Hierarchical Structure
- Procedure Inputs
- Operators & Expressions
- Defining Operators
- Words & Sentences
- User Interface Events
- What If? (Predicates)
- Recursion
- Local Variables
- Global Variables
- Word/Sentence Iteration
- Mastermind Project
- Turtles As Actors
- Arrays
- File Input/Output
Java
- A Java Program
- What's a Class?
- Extending Existing Classes
- Types
- Turtle Graphics
- Control Flow
- User Interface Events
Appendices
- Jargon
- What Is TG?
- TG Directives
- jLogo Primitives
- TG Editor
- Java Tables
- Example Programs
- Installation Notes
Updates
- December 13, 2008
- January 6, 2012
- March 15, 2013
- January 20, 2014
- February 13, 2014
- July 29, 2014
- January 18, 2016
- January 29, 2016
Lastly
Defining Procedures in the CommandCenter
Although most of the time you will use TG's Editor to enter procedure definitions, you may on occasion want to define one that you don't want included in program you are composing in the Editor. Let's walk through defining a new procedure in the CommandCenter.
First of all, when you enter a procedure definition into the CommandCenter, it behavior is a little different. Most of the time when you type instructions into the CommandCenter, something happens when you press the [Enter] key. As an example, When you type "fd 100" into the CommandCenter and press [Enter], the turtle moves forward in the graphics canvas. But, when you type in the title line of a procedure definition and press [Enter], the way TG responds is different. As Figure 4a.1 shows, the '?' prompt character you've been seeing has changed to '>' and the cursor is indented a couple of spaces.
And now as you type in the lines of instructions that make up the body of the new procedure, nothing happens in the graphics canvas. Instead, TG keeps responding to your pressing the [Enter] key with another '>' prompt character and with the cursor indented. And, it keeps doing this until you enter the end line.
Figure 4a.2 shows TG following the entering of the end line. All is back to normal.
Try this out yourself - now...
TG Programming Environment Applet |
Once you've completed the definition of the procedure you can use it like any of the Logo commands you've been using. You've just taught TG's Logo interpreter how to do something; you've added a new command to Logo's vocabulary.
Type the new procedure's name (drawO) into the CommandCenter and press the [Enter] key. Does it work?
The CommandCenter is great for adding a trivial command when you just want to experiment. But, once you've entered a line of instructions, that's it; there's no going back to change them. You must quit the current definition (either by entering an end line or by holding down the [Ctrl] key and pressing Q - the QUIT directive) and then start all over. This is not too bad since you can use the up/down arrow keys to recall previously entered lines. So, how do you know if you entered the procedure correctly?
When you type command definitions into the CommandCenter and make a mistake in the process, you don't always end up with what you think you should.
Here are a couple of directives that may help you with problems associated with user-defined procedures.
TG Directive | Description | |
---|---|---|
printprocs pp |
Print a list of the user-defined procedures that TG's Logo interpreter knows about. | |
printtext pt |
Print the text (the source code representation) of a specified user-defined procedure. | |
|
Click the mouse in the CommandCenter and type in the printprocs directive. The name of your new procedure, drawO, should be printed.
Figure 4a.3 shows what you should see.
It not, you somehow messed up the definition. Try typing the definition of drawO into the CommandCenter again.
If it is, next try typing in the printtext directive. Figure 4a.4 shows what you should see.
PRINTTEXT asks the Logo interpreter in TG to print out the definition of the procedure whose name you give it. Check out what it prints when you enter it with drawO as an input. Does it match what you thought you entered? If not, reenter the definition until it matches what one of the above examples looks like.
For the most part, you should use the Editor when programming. But, now you know an alternative which is good.