next up previous contents index
Next: Multi-Element Indexing Up: ValuesTypes, and Constants Previous: Records

Attributes

 

  All values in Glish can have attributes associated with them. Attributes contain extra information about the value. In many ways, attributes are like Glish records (see § 3.4).

Accessing Attributes Using ``::''

 

    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::shape
here b is assigned the value of a's shape attribute; b is now equal to [2, 2]. In this example, the attribute name is shape, but the name could be any string.  

If the attribute name begins with a letter or an underscore (``_'') and is followed by zero or more letters, underscores, or digits, then it can be accessed with the attribute operator with no quotes. If, however, the attribute name contains non-standard characters, the attribute name must be quoted. 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.

Accessing Attributes Using []

 

  Attributes can also be accessed much like one would access record elements using square brackets, (§ 3.4.3, page gif). One or more attributes can be 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 where the field names are the selected attribute, 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.

Accessing All Attributes

 

  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 their associated values. In this case, given the continuing example, f would equal a record with fields dim, _t12, try and T##12.  

      This operator can also be assigned to as well. All of the attributes can be set at once:

    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, and any previous attributes will be deleted. This is also the way attributes are cleared,
    f:: := [=]
This clears all of f's attributes. Unfortunately,   currently there is no way to delete individual attributes. This is a problem which should probably be resolved in the future.      

Cascaded Attributes

 

  The attribute operator is left associative, and the value of an attribute can have attributes of its own. Attribute access can be cascaded, as in:

    tmp::try::harder := 23
In this example, the value of the try attribute of tmp is given a harder attribute, and the value of this attribute is set to the scalar 23. Since tmp previously had no 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, was also retrieved; x.try::harder is equal to the scalar 23.  

 


next up previous contents index
Next: Multi-Element Indexing Up: ValuesTypes, and Constants Previous: Records

Thu Nov 13 16:44:05 EST 1997