Database Classes

Section 5.3 of Programming with Data mentions a number of different ways to define an S database, including user-defined database classes. Not much more is said about these in the book.

Here they are. The idea quite powerful; although a moderate amount of programming is needed to add a new kind of database class, the results can usually be reused for other, similar applications. This page outlines what is needed, and gives an example using the S symbolic dump format. The example has some mild practicality, in providing a portable database that could be used in a network file system over diverse hardware. It's main virtue, though, is to work out the essential ideas in a context that doesn't require discussing any other software, such as database management systems.

A database class is any class that extends the virtual class database. Attaching an object from this class causes S to look for corresponding methods for a set of basic database functions, to read, write, remove objects. Once the required set of such methods is defined, you can attach an object of this class and use the resulting database like any other.

Notice that this is different from attaching a list-like object as a database. In that case, all the data resided in the single object. For database classes, on the other hand, the database object is usually just some identifier for a directory, database, URL or whatever. It's just there to tell the evaluator to use corresponding methods to deal with the data.

Let's do an example. In this case we are going to use a directory in the file system as our database. But instead of relying on the standard S binary representation for objects, we will read and write files using the text-only "symbolic dump format" (pp 237-241). The class just needs to extend database and contain the path for the directory.



John Chambers<jmc@research.bell-labs.com>
Last modified: Wed Aug 5 17:21:10 EDT 1998