Terrapin Resources

Terrapin Logo 4 has been discontinued! Our new Terrapin Logo version is much more powerful and modern; we strongly recommend that you update to our latest release of the Logo programming language.

Objects

Create and manipulate objects.

Object commands create and destroy objects like turtles, or the objects defined in additional extensions to Terrapin Logo Pro. The built-in TELL list is often used to talk to a specific set of objects. For a description of commands around TELL, see the turtle commands. See also TELLALL, TELLODD, TELLEVEN, EACH, and WHO.

Once created, objects live forever unless you erase them with the ERASE command.

.WHO

Reports a list of objects listening to commands.

Syntax

Description

.WHO reports the list of currently active turtles, or other objects, as set by the TELL command. The output is always a list regardless of the number of objects that a previous TELL command has set. This is different to the WHO command.

See also ASK, SETTURTLES, TURTLES, and TELL.

Example

TELL 0 WHO Result: 0 .WHO Result: [0]

ASK

Makes objects execute a list of commands.

Syntax

Description

ASK causes the turtle(s) or other objects named in its first argument to execute the commands in its second argument. ASK makes it possible to send commands to a turtle that is not currently active without making it one of the active turtles.

The first argument to ask can be either a single object name or a list of object names (like turtle numbers). The input may also be any other Logo object, like a robot, or a bitmap, or a list of these objects. Logo sends the commands in the runlist to each object in the list; if one of these objects does not know the command, the execution proceeds silently. If any command outputs a value, the execution stops, and the value becomes the output of ASK. During the execution of ASK, the TELL list is set to the list that was handed to ASK as its first input; EACH, on the other hand, sets the TELL list to each of its inputs before executing the runlist.

Example

TELL 0 ASK 1 [ST] ASK 1 [FD 100] ASK 1 [HT]

CHECKTYPE

Checks an value for a type.

Syntax

Description

CHECKTYPE checks a Logo name for being an element of a certain type. Since a Logo name may be a turtle, or any other type, its properties vary from type to type. If the object given as its first input does not match the type given as the second input of CHECKTYPE, Logo throws a runtime error. A Logo name may have more than one type. The value 0 can, for example, be a number, or a turtle. CHECKTYPE can be used to check a value for being a procedure, a number, or simply anything that Logo knows.

For a list of known types, see TYPEOF.

Example

CHECKTYPE 0 “TURTLE CHECKTYPE “UNKNOWN “TURTLE

DECLARE

Also: DCL

Creates an object.

Syntax

Description

The DECLARE command allows you to create new Logo names, giving a new name a certain type. Logo uses this command internally to create objects of all kinds, like robots and turtles. When a new Logo name is declared, Logo creates the object according to its type. Note that object names must be unique, so creating a TURTLE named STAN and an ARRAY named STAN will not work.

Objects live forever until they are erased with the ERASEOBJECT command.

For a list of known types, see TYPEOF.

EACH

Applies a runlist to every object in the TELL list.

Syntax

Description

EACH causes each of the currently active objects on the TELL list to execute the commands contained in its input sequentially. Before executing the runlist, EACH sets the TELL list to each of the objects on the original TELL list. This allows each of several turtles to be given a variable input or to be addressed by WHO.

See also ASK, SETTURTLES, TURTLES, and WHO.

Example

TELLODD HOME EACH [PD SETH 30 * WHO FD 100]

EVERY

Outputs a list of objects.

Syntax

Description

The EVERY command outputs a list of those objects whose type is given as input. For a list of available types, see TYPEOF.

Example

EVERY “WINDOW Result: [EDITOR WORKSPACEVIEW TOOLBAR LISTENER TOOLBOX COLORPICKER TRACEWINDOW GRAPHICS

IS.A

Checks an object for being of a specific type.

Syntax

Description

IS.A checks a Logo name for being an object of a certain type. Since a Logo name may be a turtle, or any of the other object types, its properties vary from type to type. If the object given as the first input of IS.A matches the type given as the second input of IS.A, IS.A returns TRUE; otherwise IS.A returns FALSE. IS.A is handy for checking whether a Logo name has a certain built-in property. A Logo name may have more than one type. The value 0 can, for example, be a number, or a turtle. For a list of known types, see TYPEOF.

Example

IS.A 0 “TURTLE Result: TRUE IS.A 0 “WINDOW Result: FALSE

NEW

Creates a new Logo object.

Syntax

Description

The NEW command allows you to create new Logo objects of a certain type. The output of this command is the name of the object, which may be assigned to a Logo variable for later use. For a list of known types, see TYPEOF.

The NEW command is an abbreviation for (DECLARE :kind).

TELL

Defines a list of objects listening to commands.

Syntax

Description

TELL activates the objects that respond to turtle commands. Objects may be turtles, or other moveable objects like robots. A single number or names as an argument to TELL activates that single turtle or object. A list of numbers or names activates all the objects named in the list. Use TELLALL 0 (TURTLES - 1) to activate all available turtles. TELLEVEN and TELLODD also activate a range of turtles.

Before turtles may be activated, they must be defined by the SETTURTLES command. The default number of turtles available when Logo starts is 16. After startup or after execution of a SETTURTLES command, turtle 0 becomes the active turtle.

See also ASK, EACH, TURTLES, and WHO.

Example

TELL 0 ST PD FD 50 TELL 1 ST PD SETH 45 FD 50 TELL 0 HOME

TELLALL

Tells a range of turtle numbers.

Syntax

Description

TELLALL activates a range of turtles to respond to turtle commands. TELLALL takes two numbers as arguments. The first number is the number of the first turtle in the range to be activated. The second number is the last turtle in the range to be activated. Use TELL to activate a single turtle or a list of turtles. Additional commands that activate a range of turtles are TELLEVEN and TELLODD. EVERY “TURTLE reports a list of all available turtles.

Example

TELLALL 1 4 WHO Result: [1 2 3 4]

TELLEVEN

Tells all turtles with even numbers.

Syntax

Description

TELLEVEN activates all the even numbered available turtles. Before turtles may be activated, they must be defined by the SETTURTLES command. The default number of turtles available when Logo starts is 16. See also TELLODD, TELLALL, and WHO.

Example

TELLEVEN WHO Result: [0 2 4 6 8 10 12 14]

TELLODD

Tells all turtles with odd numbers.

Syntax

Description

TELLODD activates all the odd numbered available turtles. Before turtles may be activated, they must be defined by the SETTURTLES command. The default number of turtles available when Logo starts is 16. See also TELLEVEN, TELLALL, and WHO.

Example

TELLODD WHO Result: [1 3 5 7 9 11 13 15]

TYPEOF

Reports the type of a name.

Syntax

Description

The TYPEOF command returns the type of the Logo name supplied as input. The returned type may be one of the following words; other objects may return their type, which is not listed here.

   
ARRAY A Logo array
BOOLEAN One of the values FALSE or TRUE.
NUMBER A number.
WORD A word.
NODE A list.
NAME A Logo variable that holds a name. Note that if the variable also holds a procedure, the type is reported as PROCEDURE, since procedures take precedence over names and property lists. This type cannot be used to create a new object.
PLIST A Logo variable that holds a property list. Note that stored names and procedures take precedence over property lists. This type cannot be used to create a new object.
PROCEDURE A Logo variable that holds a procedure. Note that a procedure takes precedence over a name or a property list. This type cannot be used to create a new object.
TURTLE A turtle.

Example

TYPEOF 1.234 Result: NUMBER TYPEOF “HELLO Result: WORD

WHO

Reports a list of objects listening to commands.

Syntax

Description

WHO reports the list of currently active turtles, or other objects, as set by the TELL command. The output is either a list if there is more than one object listening, or a word, if only one object is listening. If you always need a list of objects regardless of the number of objects listening, use the .WHO command.

See also ASK, SETTURTLES, TURTLES, and TELL.

Example

TELLALL 0 3 WHO Result: [0 1 2 3] TELL 0 WHO Result: 0