Getting Started | Documentation | Glish | Learn More | Programming | Contact Us |
Version 1.9 Build 1556 |
|
All values in Glish can have attributes associated with them. Attributes contain extra information about the value. In many ways, attributes are similar to Glish records (see § 3.4).
Each attribute has a name and an associated value. Attributes can be attached to any Glish value. The attribute operator, ::, provides access to the attributes of a value. For example,
a := [1,2,3,4] a::shape := [2,2]assigns to the attribute of a named shape a vector of length two. This same operator, ::, is used to retrieve attribute values. Continuing the example from above,
b := a::shapeb is assigned the value of a's shape attribute and b is now equal to [2, 2]. In this example, the attribute name is shape, but the name can be any string.
An attribute operator is accessed without quotes if the attribute name begins with a letter or an underscore (``_'') and is followed by zero or more letters, underscores, or digits. If, however, the attribute name contains non-standard characters, the attribute name must be within quotes. So,
a::"T##12" := "quotes needed here" a::_t12 := "not here" a::try := "nor here"in this example, the attribute
T##12
requires quotes because of the hash (#
)
character.
Attributes can also be accessed using square brackets (§ 3.4.3, page ) similar to accessing record elements. One or more attributes are accessed by using a string or vector of strings:
c := a::[["_t12","try"]] d := a::["_t12 try"] e := a::['T##12']When more than one attribute is selected with square brackets, the result is a record with field names that are the selected attributes, and the values of the fields are the corresponding attribute values. In this case, both c and d equal
[_t12="not here", try="nor here"]
. e equals the string "quotes needed here".
(See § 3.4 for information on records, and § 3.3.1 for
information on string vectors.)
All of the attributes for a value can be accessed by using the attribute operator with no specified attributes, as in:
f := a::This assigns to f a record containing all of a's attributes and associated values. In this case, given the continuing example, f equals a record with fields dim,
_t12
, try and T##12
.
This operator can be assigned to as well. All attributes can be set at once, as shown below
f:: := [one="buckle", two="my", three="shoe"]In this example, all of f's attributes are set at once. After the assignment, f will have three attributes, any previous attributes are deleted. This is also the way attributes are cleared,
f:: := [=]The above example clears all of f's attributes. Currently there is no way to delete individual attributes. This problem will be resolved in the future.
The attribute operator is left associative, and the value of an attribute can have attributes of its own. Attribute access are cascaded, as in:
tmp::try::harder := 23In this example, the value of the try attribute tmp is given a harder attribute, and the value of this attribute is set to the scalar 23. Because tmp previously didn't have a try attribute, its value defaults to the boolean scalar F. Accessing tmp's attributes
x := tmp::results in x having the record value [try=F]. The harder attribute, however, is also retrieved; x.try::harder is equal to the scalar 23.