Terrapin Resources

Property lists

Add, retrieve, call, or remove properties.

Properties are values that are stored as property lists. These lists are not traditional values that MAKE and THING can handle. Instead, there are separate commands to create, to read, to set, to invoke, or to remove properties.

Many objects have built-in variables that belong to the object itself instead of the toplevel workspace. A turtle, for example, has a variable POSITION that sets or reports the turtle’s position. A turtle can be ASKed to MAKE a new position, like in ASK 0 [MAKE “POSITION [100 100]]. Alternatively, these object specific variables may be accessed as properties of that object. Instead of ASKing a turtle like above, you can set the turtle’s POSITION property as in PPROP 0 “POSITION [100 100].

CPROP

Calls a property as a procedure.

Syntax

Description

Many objects contain built-in procedures. Use the CPROP (Call PROPerty) command to call a procedure of an object. Such a procedure definition is a special kind of property that GPROP and PPROP cannot access. The CPROP command accepts the name of the object, the name of the procedure, and optionally, further inputs to that procedure. It may or may not output a value.

Getting or setting properties is usually not a problem if the property does not exist. An attempt to call a non-existing or non-callable property is an error, however.

Example

Loads an image into a bitmap.

DCL “BITMAP “DIE (CPROP “DIE “LOAD “|~home/toolbox/dice/dice123|)

GLIST

Reports the property lists that contain a property with a given name.

Syntax

Description

GLIST takes as input the name of a property, a quoted word, and reports a list of all currently defined properties that have a value for that name.

Example

PPROP “HERMAN “AGE 24 PPROP “GRISELDA “AGE 36 PPROP “GRISELDA “MOTHER “WINIFRED GLIST “AGE Result: [HERMAN GRISELDA] GLIST “MOTHER Result: [GRISELDA]

GPROP

Retrieves a property.

Syntax

Description

GPROP reports the property value of a name that has been assigned a property with PPROP. If the property list does not exist, GPROP reports the empty list. GPROP also reports the built-in property values for objects like bit maps, or turtles. See also GLIST, PLIST, PPROP, CPROP, PPROPS and REMPROP.

Example

PPROPS “CAR [TIRES 4 DOORS 2] GPROP “CAR “TIRES Result: 4 GPROP “CAR “DOORS Result: 2 GPROP “CAR “MPG Result: []

PLIST

Reports the property list of a name.

Syntax

Description

PLIST reports the property list associated with its input. The property list is a list of a property name or names paired with its property value or values. PLIST stands for “Property LIST.” PLIST is handy for retrieving the state of a turtle, bitmap, or other objects. Note that the PLIST command only returns those properties that actually have a value; properties that are write-only, or callable properties are not returned. See also GLIST, GPROP, PPROP, PPROPS, POPLS and REMPROP.

Example

PPROP “SHOES “SIZE 6 PPROP “HAT “COLOR “BROWN PLIST “SHOES Result: [SIZE 6] PLIST “HAT Result: [COLOR BROWN]

PPROP

Stores a property.

Syntax

Description

PPROP assigns a property pair to a Logo name. PPROP takes three inputs: the name with which a property list should be associated, the property name, and the property value. The first input to PPROP must be a word, a turtle number, or the name of an object; the second input must be a word, and the third input can be either a word or a list. PPROP stands for “Put PROPerty.” A property pair consists of a property name and its value. PPROP can also be used to alter the properties of turtles, bitmaps, and other objects. See also GPROP, CPROP, GLIST, PLIST, POPLS, PPROPS, and REMPROP.

Example

PPROP “MUSIC “COMPOSER “STRAVINSKY PPROP “MUSIC “COMPOSITION “PETROUCHKA PLIST “MUSIC Result: [COMPOSER STRAVINSKY COMPOSITION PETROUCHKA]

PPROPS

Stores a list of properties.

Syntax

Description

PPROPS is a handy method to store multiple properties into a property list. The second input to PPROPS is a list of property pairs. The first word in the pair is the property, the second item in the pair is the property value for that property. The list must be of even length. PPROPS is handy for assigning multiple properties to turtles, bitmaps, and other objects. See also GPROP, POPLS , PPROP, and REMPROP.

Example

PPROPS “JOE [GENDER MALE AGE 24 ADDRESS [23 OAK STREET]] GPROP “JOE “AGE Result: 24 GPROP “JOE “GENDER Result: MALE GPROP “JOE “ADDRESS Result: [23 OAK STREET]

REMPROP

Removes a property.

Syntax

Description

REMPROP removes a property and its value from the name with which it is associated. REMPROP stands for “REMove PROPerty.” Built-in properties of objects cannot be removed. The name may also be the number of a turtle, or the name of another object. ERASE erases everything in memory, including all property lists. See also GPROP, GLIST, PLIST, POPLS, and PPROP.

Example

PPROP “DOG “LEGS 4 PLIST “DOG Result: [LEGS 4] REMPROP “DOG “LEGS PLIST “DOG Result: []