Acquired Attributes and structure

A member of a class can acquire an attribute that is not a class attribute declared in the class definition. Such an attribute is called an acquired attribute. To add such an attribute to a member, we only need to use an assignment statement
A.attrib_name = value;
For example
x.color = "red";

Acquired attribute definition may also carry a domain.

x.color = "red" in {"red", "gree", "blue"};
Specification of domain can occur only at the first time the attribute is defined (the first time a value is assigned to the attribute). If domain is not given, the attribute will have the default domain, which is the set _ALL. Subsequent assignment to the attribute can no longer specify a new domain, and the assigned value must belong to the domain of the attribute.

A structure is an object which doesn't belong to any class. It therefore has no class attribute and only has acquired attributes. To define such an object, just enclose all attributes in a pair of braces.

solution = {x = 3.8, y = -5.2};

New acquired attributes can be added to the object and updated at any time, and domain can be specified when it's added.

It is worth mentioning at this time that the keyword global is a actually structure that can be accessed in any scope. The attributes of global function as global variables.

oz 2009-12-22