8 A Simple Library
In this chapter, we create a complete library that represents time and position. The timespace library provides the say generic function for all concrete classes, the mathematical function + on certain kinds of time, and the comparison functions < and =, which enable users to call all other numerical comparisons, >, >=, <=, and ~=. Our library consists of four files:
The LID file lists all the files in the
timespacelibrary.The library file defines the
timespacelibrary and thetimespacemodule.The implementation file defines the classes, methods, and generic functions.
The test file creates instances, calls
sayon them, and adds time instances.
We provide the test file so that you can experiment with the library. Because the test code has a purpose different from that of the implementation code, we separate them into two files. Normally, a finished library would not contain both the implementation and the test code — the test code would be in a separate library. However, when you are starting to implement your program or library, it is convenient to put all the code in one library, as we do here.
We shall continue to develop the time and position library in Part II. The complete version is given in Chapter 14, Four Complete Libraries.




