Structure
|
A Structure is a table with two columns. The left column contains symbolic keys, and the right column contains the value associated with its respective symbolic key.
A Structure has a variable number of rows; however, a Structure always has exactly two columns (the symbolic keys and the values associated with those symbolic keys). Both the keys and values are available at run time, and the Structure can be sorted by keys or values, can have keys added, altered, or deleted dynamically.
A Structure Object is analogous to a table containing exactly two columns and an arbitrary number of rows. The left column contains a key (must be an Object type: Symbol, List, Pair , any Vector type, Structure, Dictionary, Repository, or Lambda ) , and the right column contains the value associated with its key. Any given row in a table is analogous to a Structure binding of a Key/Value pair.
Name | John Doe |
Salary | $55000 |
Address | 184 Anywhere St. |
City | Los Angeles |
State | California |
We can sort the structure by key in descending order. Using the Structure above, the resulting sorted structure is:
State | California |
Salary | $55000 |
Name | John Doe |
City | Los Angeles |
Address | 184 Anywhere St. |
Structures are convenient for storing Key/ Value pairs in unsorted order. They have a relatively small overhead compared to Dictionaries or Directories which sorts these key value pairs automatically.
An Analytic Information Server Structures are similar to the user-defined type of Visual Basic. The Visual Basic user defined type is created at compile time, whereas the Analytic Information Server structure is created, expanded, or contracted dynamically at run time. The main difference is that the Visual Basic user defined type is static and the Analytic Information Server structure is dynamic, and the object keys offer a wider range of values.
Type Employee
Name As Variant ' Name of the employee.
Salary As Variant ' Salary of the employee.
Address As Variant ' Address of the employee.
City As Variant ' City of the employee.
State As Variant ' State of the employee.
End Type
The Structure data type supports a simple constant form. The whole Structure constant is enclosed in braces and preceded by the sharp symbol and a left-brace (#{ ... }) and terminated with a right-brace. Some Structure constant examples:
#{Name: "John Doe" Address: "184 Anywhere Street" City: "Los Angeles" State: "California"}
The constant form for Structures allows embedded Analytic Information Server objects for the values or keys as follows:
#{X: 5 Y: #{Mike: "father" Sally: "mother"} Z: "Hello"}
#{Date: #Jan,1 ,1972 Manager: #{Name: "Joe Smith" Age: "45"} Employee: #{Name: Jan Brown Address: "28"}}
The Structure data type also supports a strongly-typed declarative form. The declarative Structure constant is enclosed in braces and preceded by the sharp symbol, a left-brace, and the decl notation (#{decl| ... }), and terminated with a right-brace. Some declarative Structure constant examples:
#{decl| (String:Name "John Doe") Number:Salary}
Note: The declarative constant form, shown above, supports the same variable declaration and initialization syntax as in the args:(), vars:(), svars:(), pvars:(), and cvars:() sections of the lambda special form. See the lambda special form for additional information on variable declaration.
The Structure is a Heap Object or an Object Data Type. The Analytic Information Server Object Types are stored in the Heap and are managed by the Heap manager. The Analytic Information Server Heap manager supports object resizing, garbage collection, and anti-fragmentation algorithms so that the user may concentrate on the analysis and modeling of data rather than on memory management. Without exception, all of the Object types are identified by an object id. The object id identifies a block of memory, managed by the Lambda Information Server memory manager, in which the Object's data is stored.
The Analytic Information Server Heap Object and Native Data types can be saved and loaded to and from persistent (disk file) storage at any time. Containers with immediate data are saved on disk in fixed length records equal to the size of the container. Containers with Heap object references are saved in fixed length records, which are automatically expanded to include the contents of the Heap object, and any objects referenced by the Heap object, etc. This feature is called Object Closure Management and is automatic with every Analytic Information Server container database save.
Analytic Information Server containers may be loaded from any database repository record at any time. If the data in the record is immediate, the database load fills the container with the immediate data. If the data in the record is an object closure, the database load fills the container with a Heap object reference, and all of the objects in the record are loaded back into the Heap with the same referential relationships they had when they were saved in the repository.
NOTE: The Structure is a special type in AIS Lisp. Structures are used to store the strongly-typed templates for all class variables, persistant variables, constant variables, and temporary variables. In addition, strongly-typed user-defined Structure templates can be declared using the declarative constant form of the Structure.
The Structure object can be demonstrated by the following examples.