Terrapin Resources

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.

You can also use ASK to ask a control to perform certain actions that are specific to the control (for that matter, we are talking about any callable properties at any object). For example, you can ASK a list box to APPEND an item instead of having to use the Object properties for such commands.

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.

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 ERASE command.

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.

You can also use EACH to ask a control to perform certain actions that are specific to the control (for that matter, we are talking about any callable properties at any object). For example, you can use EACH to ask a list box to APPEND an item instead of having to use the Object properties for such commands.

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.

Example

EVERY “PANEL Result: [GRAPHICS LISTENER TOOLBOX FILES HELP EDITOR DEBUGGER]

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. Logo knows several types, and the list keeps growing. Buttons, sliders, and other controls have their own type, but all controls are also CONTROLs. In addition, controls, turtles, and bitmaps are also WIDGETs.

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. 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. Logo knows several types, and the list keeps growing. Buttons, sliders, and other controls have their own type, but all controls are also CONTROLs. In addition, controls, turtles, and bitmaps are also WIDGETs.

Example

TYPEOF 1.234 Result: NUMBER TYPEOF “HELLO Result: WORD ; Note that object or widget names take precedence! TYPEOF 0 Result: TURTLE

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