Views


The Automatic Programming Server produces versions of generic procedures that are specialized for your data structures. Views describe how your data structures correspond to the abstract data types used in the generic procedures.

In most programming languages, procedures are strongly typed, and any call to the procedure must use the same types that are used in the definition of the procedure. Thus, to reuse someone else's procedure, you must understand the types they use and conform to those types.

With views, you only need to describe how your data correspond to the abstract data used in the generic procedures. User interfaces are provided that make the views for you, either automatically or based on a few simple choices that you specify. There are two systems for making views: one for data structure views, and one for mathematical views.

Before making views, you must define your data structure(s). Then click the Make a View command. The system will present menus and/or a graphical interface to allow you to specify the view.


Data Structure Views

A data structure view describes how a user data structure matches an abstract data type such as a linked-list. The data structure views that are available include:

In general, these data structures contain pointers to other data of the same type. If your data structure contains such pointers, the view will be made using those pointers. Otherwise, the system will define a "carrier record" that contains your data plus the necessary pointers.

If there is more than one choice for an item, the system will present a menu to allow you to select the choice to be made. In some cases, the system can make the view automatically. In other cases, it will ask questions, such as what field to sort on and whether the sort should be ascending or descending.

An example data declaration for a person data structure is:

(person (name   string)
        (age    integer)
        (salary real)
        (friend (^ person)))
This data structure could be viewed as a linked-list using the friend pointer as the link field. It could also be viewed as a sorted-linked-list with sorting on name, age, or salary.

Mathematical Views

Mathematical views describe how user data correspond to mathematical abstract data. For example, the vector abstract type used by the generic procedures is an (x,y) vector, but your vector type might be a polar (r,theta) vector.

The mathematical views that are available include:

When you request a mathematical view, a graphical window is created that gives a diagram of the mathematical object and a menu of the fields available from your data. The diagram contains labeled "buttons" for parameters of the mathematical object. To make a view, click the mouse on a diagram button; then click the corresponding item in the menu of your data. A line is drawn between the selected items to show the correspondence. When a sufficient definition of the object has been specified, click the Done command.

As a simple example, suppose that the data type pizza has been defined:

(pizza (diameter real)
       (topping string))
To view a pizza as a circle, click the mouse on the d button of the circle diagram, then click the diameter in the menu of the pizza data type. Then click the Done command. Then you can select Make Programs to make a program to calculate, say, the area of a pizza.