| ||
Modularization: A Concrete Example |
Many object oriented languages have a basic inheritance hierarchy where ordered entities inherit from an Ordered class, such that the commonalities for all classes of ordered entities can be factored out. There is no tradition to do this in the BETA family of languages, but it is possible to write some patterns that implement such a hierarchy. The following example does just that (in gbeta, of course). First we must establish a universe wherein everything can be placed:
This is a minimal basic library; this would normally be provided as part of the language implementation, but there is nothing magic about it so we show it here along with the other files. For brevity we just include the few things which are actually used, and we even leave out methods to print numbers. The name stdio denotes a primitive (built-in) entity which provides access to the standard input and standard output. Note the lib:attributes slot; such a slot is conventionally defined in betaenv, and it provides us with a "global" namespace. We also have a program:merge slot; this slot is a placeholder for the program, so all we need to do when we write programs is to claim this place. The following fragment does just that:
The --program:merge-- syntax means "Here comes the piece of code which is called program (and it is syntactically a merge construct)". The INCLUDE properties ensure that the other fragments we need will be included, and the ORIGIN property specifies that the place where the piece of code called program is used is in betaenv. This is the main program, in the sense that it is the intended argument to gbeta, it contains the application code which uses the libraries (the remaining files), and it ties all the pieces together. The next section presents the missing pieces. |