Logo Lesson 2 Logo Procedures TBE 540-40 Fall 2004 Farah Fisher.

36
Logo Lesson 2 Logo Procedures TBE 540-40 Fall 2004 Farah Fisher
  • date post

    22-Dec-2015
  • Category

    Documents

  • view

    223
  • download

    0

Transcript of Logo Lesson 2 Logo Procedures TBE 540-40 Fall 2004 Farah Fisher.

Page 1: Logo Lesson 2 Logo Procedures TBE 540-40 Fall 2004 Farah Fisher.

Logo Lesson 2Logo Procedures

TBE 540-40

Fall 2004

Farah Fisher

Page 2: Logo Lesson 2 Logo Procedures TBE 540-40 Fall 2004 Farah Fisher.

Lesson Prerequisites

Before beginning this lesson, the student must be able to…

Start the Logo program (appropriate version) Create simple shapes using FD, BK, LT, RT,

REPEAT Use pen control commands such as PU, PD, PE,

PPT (PP) Change pen color and background color using

SETPC or SETBG or a menu

Page 3: Logo Lesson 2 Logo Procedures TBE 540-40 Fall 2004 Farah Fisher.

Lesson Objectives

After completing this lesson, the student will be able to…

Explain the concept of Logo procedures Create a new Logo procedure Edit an existing Logo procedure Execute (run) a Logo procedure Save and load workspaces List all procedures in a workspace using POTS

Page 4: Logo Lesson 2 Logo Procedures TBE 540-40 Fall 2004 Farah Fisher.

What is a Logo procedure?

When you used Logo in Lesson 1, each time you typed a command (or set of commands), the turtle moved immediately.

However, the turtle did not “remember” how to make the shape. To create the shape again, you needed to type the commands again.

A procedure is a way to make the turtle remember a set of commands.

Page 5: Logo Lesson 2 Logo Procedures TBE 540-40 Fall 2004 Farah Fisher.

What is a Logo procedure?

Each procedure is given a name (e.g., SQUARE or HOUSE or BIG.RED.THING). The name may not include spaces.

Creating the procedure is like teaching the Logo turtle the meaning of a word.

For example, we can teach the turtle that the word SQUARE means REPEAT 4 [FD 50 RT 90]

Afterwards, every time we type the word SQAURE, the turtle will know what to do.

Page 6: Logo Lesson 2 Logo Procedures TBE 540-40 Fall 2004 Farah Fisher.

What is a Logo procedure?

Procedures are kept in memory as part of a Logo workspace.

The workspace is a collection of all the Logo procedures currently in memory.

These workspaces can be save and loaded, just like other documents.

More information about workspaces will be presented later.

Page 7: Logo Lesson 2 Logo Procedures TBE 540-40 Fall 2004 Farah Fisher.

How do you create a procedure?

Various versions of Logo may ask that you begin procedures in different ways.

This lesson will show two of the most common ways to start making a procedure.

Check the manual or HELP function of your version of Logo for more information.

Page 8: Logo Lesson 2 Logo Procedures TBE 540-40 Fall 2004 Farah Fisher.

Creating a Procedure using TO

All Logo procedures actually have the word TO as part of the name (e.g., TO SQUARE or TO HOUSE).

All versions of Logo allow this method for creating procedures.

To begin a procedure, type the word TO and a name for the procedure.

For example, you could type TO MY.NAME or TO TRIANGLE

Page 9: Logo Lesson 2 Logo Procedures TBE 540-40 Fall 2004 Farah Fisher.

Creating a Procedure using TO

You will see a symbol like this: > The symbol means “it is your turn to type

something”. Type one or more Logo commands and press

Return/Enter. Another > will appear. After you have finished all commands, type END

at the > symbol. NOTE: You cannot immediately edit a previous

line using this method. You must edit later.

Page 10: Logo Lesson 2 Logo Procedures TBE 540-40 Fall 2004 Farah Fisher.

Creating a Procedure using EDIT

All versions of Logo allow you to edit an existing procedure using the command EDIT.

Some versions of Logo also allow EDIT to be used to create new procedures (check your HELP file or manual).

To begin a new procedure or edit an old one, type the word EDIT, a quote and the procedure name. Example: EDIT “SQUARE

Page 11: Logo Lesson 2 Logo Procedures TBE 540-40 Fall 2004 Farah Fisher.

Creating a Procedure using EDIT

There are several things to notice when using the EDIT command (e.g., EDIT “HOUSE.BOAT) There is a space after the word EDIT. There is no space between the quote and the name of

the procedure. There is no quote after the procedure name.

Many Logo commands follow this pattern.

Page 12: Logo Lesson 2 Logo Procedures TBE 540-40 Fall 2004 Farah Fisher.

Creating a Procedure using EDIT

You will probably see the following two lines in the editing window when you begin a new procedure: TO SQUARE (or whatever you specified as the name) END

You will be typing the commands between these two lines, so you may need to press Return/Enter to open up space to type.

Page 13: Logo Lesson 2 Logo Procedures TBE 540-40 Fall 2004 Farah Fisher.

Creating a Procedure using EDIT

Finishing and saving a procedure using EDIT will depend on the version of Logo you are using.

There may be a menu item such as “Save and Exit”.

There may be a specific command on the keyboard.

The simplest way is to attempt to close the editing window. The computer should ask if you want to save the changes.

Page 14: Logo Lesson 2 Logo Procedures TBE 540-40 Fall 2004 Farah Fisher.

The Logo Workspace

Earlier in this lesson, a workspace was defined as a collection of procedures in memory.

Every time you create and save a procedure, it becomes part of the current workspace.

NOTE: Saving a procedure does not put it on a disk. It exists only in memory until the entire workspace is saved.

Page 15: Logo Lesson 2 Logo Procedures TBE 540-40 Fall 2004 Farah Fisher.

The Logo Workspace

The POTS command (Print Out Titles) shows you a list of all the procedures in memory.

In the list, each procedure name will have the word TO in front of it. For example (the ? is the prompt in most Logo versions - no need to type it):? POTSTO SQUARETO TRIANGLETO HOUSE

Page 16: Logo Lesson 2 Logo Procedures TBE 540-40 Fall 2004 Farah Fisher.

Saving a Logo Workspace

To save a workspace on disk (including all procedures in memory), type SAVE “filename

The filename may be anything that is appropriate for your operating system. In some versions of Logo, an extension of .LGO will be added to the end of the filename.

There may be a menu item for SAVE in some versions of Logo.

Page 17: Logo Lesson 2 Logo Procedures TBE 540-40 Fall 2004 Farah Fisher.

Loading a Logo Workspace

To load a workspace that has previously been saved to disk (including all procedures in memory), type LOAD “filename

All procedures will come into memory. If some procedures are in memory before the LOAD, the new ones will simply be added to the POTS list.

There may be a menu item for LOAD in some versions of Logo.

Page 18: Logo Lesson 2 Logo Procedures TBE 540-40 Fall 2004 Farah Fisher.

Summary of Steps to Create a Logo Procedure Decide what commands will be included in your

Logo procedure and think of a name for it (with no spaces)

In your Logo program, do one of the following: Type TO and the procedure name (TO SQ) Type EDIT “ and the procedure name (EDIT “SQ)

Enter the commands in the procedure.

Page 19: Logo Lesson 2 Logo Procedures TBE 540-40 Fall 2004 Farah Fisher.

Summary of Steps to Create a Logo Procedure When you have finished the procedure, exit and

save using one of these methods: If you began with TO, type END on the last line. If you began with EDIT, close the window and save (or

use the appropriate menu choice or keys)

Your procedure will become part of the POTS list.

Page 20: Logo Lesson 2 Logo Procedures TBE 540-40 Fall 2004 Farah Fisher.

Summary of Steps to Create a Logo Procedure Create other procedures as necessary. Remember to SAVE the workspace on disk so

that you can use it again (e.g., SAVE “FIRST)

Page 21: Logo Lesson 2 Logo Procedures TBE 540-40 Fall 2004 Farah Fisher.

“Running” a Logo Procedure

After you have created a procedure, you will want to see if it works.

Type the name of the procedure (without TO) to begin.

For example, if the procedure is listed as TO THING, type THING to start the procedure.

Use EDIT “procedurename to correct mistakes.

Page 22: Logo Lesson 2 Logo Procedures TBE 540-40 Fall 2004 Farah Fisher.

Procedure Names as Logo Commands After you have created a Logo procedure, you can

use its name as a command in another procedure. NOTE: The procedure name you use must be in the current POTS.

For example, if you have created a procedure called TO SQUARE, you can include the command SQUARE in a procedure called TO HOUSE.

Page 23: Logo Lesson 2 Logo Procedures TBE 540-40 Fall 2004 Farah Fisher.

Procedure Names as Logo Commands Example:

TO TRIANGLEREPEAT 3 [FD 50 RT 120]ENDTO WINDMILLREPEAT 4 [TRIANGLE RT 90]END

Page 24: Logo Lesson 2 Logo Procedures TBE 540-40 Fall 2004 Farah Fisher.

Self Check for Lesson 2

A Logo procedure is… A shape that you make with the turtle. A set of commands stored together under one name. A logo command (e.g. PROCEDURE 7)

Page 25: Logo Lesson 2 Logo Procedures TBE 540-40 Fall 2004 Farah Fisher.

Self Check for Lesson 2

A Logo procedure is… A shape that you make with the turtle. A set of commands stored together under one name. A logo command (e.g. PROCEDURE 7)

Page 26: Logo Lesson 2 Logo Procedures TBE 540-40 Fall 2004 Farah Fisher.

Self Check for Lesson 2

To begin entering a Logo procedure called GREEN, you should type… BEGIN “GREEN EDIT “GREEN TO GREEN

Page 27: Logo Lesson 2 Logo Procedures TBE 540-40 Fall 2004 Farah Fisher.

Self Check for Lesson 2

To begin entering a Logo procedure called GREEN… Type BEGIN “GREEN EDIT “GREEN {Most version of Logo TO GREEN allow either of these.}

Page 28: Logo Lesson 2 Logo Procedures TBE 540-40 Fall 2004 Farah Fisher.

Self Check for Lesson 2

After creating the procedure called GREEN, to start it you would type… BEGIN “GREEN “GREEN GREEN RUN “GREEN

Page 29: Logo Lesson 2 Logo Procedures TBE 540-40 Fall 2004 Farah Fisher.

Self Check for Lesson 2

After creating the procedure called GREEN, to start it you would type… BEGIN “GREEN “GREEN GREEN Just type the procedure name RUN “GREEN

Page 30: Logo Lesson 2 Logo Procedures TBE 540-40 Fall 2004 Farah Fisher.

Self Check for Lesson 2

When you type POTS, you see… A list of all procedures in memory. A picture of a pot. A list of all files on the disk. A list of all possible Logo commands

Page 31: Logo Lesson 2 Logo Procedures TBE 540-40 Fall 2004 Farah Fisher.

Self Check for Lesson 2

When you type POTS, you see… A list of all procedures in memory. A picture of a pot. A list of all files on the disk. A list of all possible Logo commands

Page 32: Logo Lesson 2 Logo Procedures TBE 540-40 Fall 2004 Farah Fisher.

Self Check for Lesson 2

When you type SAVE “BASICS The procedure called BASICS is saved on the disk. The picture called BASICS is saved on the disk. All the procedures in POTS are saved on the disk in one

file called BASICS. Each of the procedures in POTS is saved on the disk

under its own name.

Page 33: Logo Lesson 2 Logo Procedures TBE 540-40 Fall 2004 Farah Fisher.

Self Check for Lesson 2

When you type SAVE “BASICS The procedure called BASICS is saved on the disk. The picture called BASICS is saved on the disk. All the procedures in POTS are saved on the disk in one

file called BASICS. Each of the procedures in POTS is saved on the disk

under its own name.

Page 34: Logo Lesson 2 Logo Procedures TBE 540-40 Fall 2004 Farah Fisher.

Self Check for Lesson 2

To get the procedures in the BASICS file back into POTS (the workspace), type UNSAVE “BASICS GET “BASICS LOAD “BASICS You cannot retrieve the files once they have been saved.

Page 35: Logo Lesson 2 Logo Procedures TBE 540-40 Fall 2004 Farah Fisher.

Self Check for Lesson 2

To get the procedures in the BASICS file back into POTS (the workspace), type UNSAVE “BASICS GET “BASICS LOAD “BASICS You cannot retrieve the files once they have been saved.

Page 36: Logo Lesson 2 Logo Procedures TBE 540-40 Fall 2004 Farah Fisher.

Try some Logo procedures

See the hands-on exercise at http://www.csudh.edu/fisher/tbe540/LEX2.htm

Possible answers are found at http://www.csudh.edu/fisher/tbe540/HO2ans.htm