General:. Record Sets in
Glee are like tables of structures in other languages. A Record
Set is composed of two objects: (1) A field list (naming fields within
records), and (2) a sequence of records(which are themselves sequences of data
elements in field order). A Record Set can be viewed as a table with named
columns. Glee facilitates creating the Record Set; defining its
fields; populating its records; adding, deleting, and renaming fields;
replacing and deleting records; and retrieving by field, by record, or by
combination of both. Glee Record Sets do not impose discipline on
the data. They merely provide a mechanism for naming and thereby referring to
elements of a record sequence. For example, you can put string data where
numerics belong and the Record Set does not debate. Glee will,
however, assure that there is a correspondence between the field names and the
fields in all the records. When data is submitted, Glee scans it
for conformity and rejects all or accepts all. If rejected, a diagnostic is
given and the program is interrupted. Use of Record Sets can make programs more
readable.
Create Record Set
(#RS): The niladic operator "#RS" creates a
Record Set with no fields and no records. It is simply a composite object with
an empty field list object and a record sequence containing no elements. You
can assign this to a variable which can then be the target for populating the
Record Set.
Add fields to new Record
Set: Fields are added to Record Sets by assigning to an empty Record Set
index. You can add fields at any time. Glee checks to be sure the
field you are adding is not already part of the Record Set object. If it is, a
diagnostic is given and the program is interrupted. If not, the field is
appended to the field list for the Record Set. If the Record Set contains
records, new items are appended to each record. These items are a null objects.
Create with field list: It
is common to create the Record Set with its initial complement of fields rather
than to add fields later.
Rearranging and deleting
fields in a Record Set: Record Set fields are maintained in the order in
which they are supplied. New fields are appended to the field list. If
you want to change this order or remove fields, you do so by field
indexing into the Record Set. This creates a new Record Set in the new
order. You can then replace the existing Record Set with it. Record Sets are
just collections of pointers. However, when you rearrange fields, you are
rearranging the elements of the record sequences as well. If the Record Set is
very large, this is probably not a good idea. Records Sets should probably not
be allowed to grow to great size. They are intended for managing small tables
of data.
Add Records: Data records
are added to Record Sets by assigning to an empty Record Set index. This is the
same method we used for adding fields. When you append new records to the
Record Set using null indexing (i.e. []) the field order of the Record
Set is assumed. This can be obtained using the :fields property for
the Record Set (e.g. rs.fields). This example also illustrates adding
a field after the Record Set contains records. NULL elements are added to each
existing record for the new field.
The .rec method and mnemonic
programming: You can construct more readable and managable programs using
mnemonic techniques. This example shows how you can get an empty record
structure from the Record Set using the :rec method. A copy of the
Record Set is returned which contains just one record of which all fields are
null objects. You can then mnemonically index the field data into this record
and then append it to the Record Set. This technique might be useful for
creating records and populating them as data is received from a form.
Addressing: Addressing in
Record Sets can be by record(s); by field(s); or by a combination as shown
here. When using the combination, specify the field(s) together (in the order
you want) and the record number(s) (in the order you want). It doesn't matter
which order you use (fields first or record numbers first). In fact you can mix
them up but I don't recommend that.
Editing fields and records:
You can address fields and records directly in the record set and edit
accordingly.
:Using At Each (@&) to
avoid ambiguity: It this example I create two records (r1 and
r2) each containing two fields. My Record Set has two fields
(.f1 and .f2). I then add r1 and r2 to the
Record Set with r1 r2 @& => []rs. The
"@&" tells Glee to take the elements of
the sequence at each row rather than as two fields. Since each of these
records contains the requisit two fields, Glee has conformity.
Assign to field: Caveat:
Glee is still experimental and Record Sets are really experimental This
is a very clumbsy illustration of assigning into a field of a record set. It is
clumbsy because I haven't thought everything through yet. Now the example:
I am creating a two field table (.n and .c). The
".n" field will contain the ascii numeric value and the
".c" field will contain its corresponding character. I begin
by creating a Record Set containing on the ".n" field
(.n #rs => t;). Let the clumbsyness begin. I add the records for
numerics (65..67 @& @& =>[]t;). The first "at
each" (@&) is monadic. It takes the numeric vector and makes
from its elements a sequence of single element numeric vectors. The second
"@&" marks the resulting sequence as an "at each
sequence". If I did not do this, the assignment (=>[]t) would
be taken as adding one record to "t". But I intend to add 3
records; the "@&" removes the ambiguity. I add the field
for the characters (.c=>[]t;). The clumbsyness continues. Now I use
the ".n" field to populate the corresponding
".c" field data with (t[.n]:recs < @& #asc @&
=>[.c]t ;). The (t[.n]) gives me a Record Set containing just
the ".n" field. The ".recs" method gives
me the sequence of fields from that record set. This is a sequence of
sequences. The "<" discloses this homogeneous sequence so
I now have a sequence of single element numeric vectors. The first
"@&" marks the sequence as an each sequence so
the operator "#asc" will apply to each element of the
sequence rather than the sequence as a whole. "#asc" takes
the numeric argument and returns 1 element string of the ascii character
corresponding to the number. The result is a sequence. The second
"@&" marks this sequence so it will be taken by the
assignment (=>[.c]t) as rows.