6.1.4 Record Creation

To illustrate record creation, we will use the example declarations we used earlier:
type element_record = record [ name : array [ character ];
                               number : integer;
                               weight : real ]
type atomic_table = array [ element_record ];
When creating items of record types, we specify the matched pairs of field names and contents, in the order given in the type definition. Here are examples:
let hydrogen := record element_record [ name: "Hydrogen"; number: 1;
                                            weight: 1.0 ];
    helium   := record element_record [ name: "Helium"; number: 2; 
                                        weight: 4.0 ];
    element_115 := record element_record [ name: ""; number: 115;
                                           weight: -999.999];
    column1 := array atomic_table [ 1: hydrogen, helium, element_115 ]

in hydrogen, helium, element_115, column1
end let
Here we see three records being created, each of which has its type, element_record, specified along with it. This is sometimes optional, but it's a good practice to adopt, nonetheless, as it helps clarify the code to human readers. The first two records, hydrogen and helium have their field names and values specified in the order given in the original declaration, and with reasonable values. The field names must be paired with the field values, with a colon separating each name and value, and a semicolon separating the pairs, as in the definition of the type. In the third record, element_115, we see and empty string used for the name and a negative value for the weight, used as flag values. This is still a legal record, since all the fields are specified in order and with correct types.

The fourth item created and returned above is an array named column1 of type atomic_table. We will see more about creating arrays in the next section.



Previous Section



Next Section



Table of Contents




If you have any questions about this page, or want more information about the Sisal Language Project, contact:
John Feo at (510) 422-6389 or feo@diego.llnl.gov, or Tom DeBoni at (510) 423-3793 or deboni@llnl.gov.

The Sisal Language Project has been approved as a Designated Unclassified Subject Area (DUSA) K19222, as of 07 August, 1991.

LLNL Disclaimer
UCRL-MI-122601