Four Complete Libraries ======================= In this chapter, we show all the files that the complete ``time``, ``angle``, ``sixty-unit``, and ``say`` libraries comprise. The ``sixty-unit`` library -------------------------- The ``sixty-unit`` library is an example of a shared substrate library. Both the ``time`` and ``angle`` libraries use the ``sixty-unit`` library to create more specialized classes that build on a common substrate. The ``sixty-unit`` library comprises two Dylan interchange-format files: a library file, containing the library and module definitions; and an implementation file, containing a single source record, defining the generic function that is the ``say`` protocol. For completeness, we also show the LID file that describes the library and its component files. The ``sixty-unit-library`` file ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The ``sixty-unit-library`` file: ``sixty-unit-library.dylan``. .. code-block:: dylan Module: dylan-user // Library definition define library sixty-unit // Interface module export sixty-unit; // Substrate library use dylan; end library sixty-unit; // Interface module define module sixty-unit // Classes create ; // Generics create total-seconds, encode-total-seconds, decode-total-seconds; end module sixty-unit; // Implementation module define module sixty-unit-implementation // External interface use sixty-unit; // Substrate module use dylan; end module sixty-unit-implementation; The ``sixty-unit`` implementation file ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The ``sixty-unit`` implementation file: ``sixty-unit.dylan``. .. code-block:: dylan Module: sixty-unit-implementation define open abstract class () slot total-seconds :: , required-init-keyword: total-seconds:; end class ; define method encode-total-seconds (max-unit :: , minutes :: , seconds :: ) => (total-seconds :: ) ((max-unit * 60) + minutes) * 60 + seconds; end method encode-total-seconds; define method decode-total-seconds (sixty-unit :: ) => (max-unit :: , minutes :: , seconds :: ) decode-total-seconds(sixty-unit.total-seconds); end method decode-total-seconds; define method decode-total-seconds (total-seconds :: ) => (max-unit :: , minutes :: , seconds :: ) let (total-minutes, seconds) = truncate/(abs(total-seconds), 60); let (max-unit, minutes) = truncate/(total-minutes, 60); values(max-unit, minutes, seconds); end method decode-total-seconds; The ``sixty-unit`` LID file ~~~~~~~~~~~~~~~~~~~~~~~~~~~ The LID file: ``sixty-unit.lid``. .. code-block:: dylan library: sixty-unit files: sixty-unit-library sixty-unit The ``say`` library ------------------- The ``say`` library is an example of a library that defines a shared protocol. All our other libraries use the ``say`` library, so that they can add to the ``say`` generic function methods that appropriately display the objects of the classes that they define. The ``say`` library comprises two Dylan interchange-format files: a library file, containing the library and module definitions; and an implementation file, containing a single source record, defining the generic function that is the ``say`` protocol. For completeness, we also show the LID file that describes the library and its component files. The ``say-library`` file ~~~~~~~~~~~~~~~~~~~~~~~~ The ``say-library`` file: ``say-library.dylan``. .. code-block:: dylan Module: dylan-user // Library definition define library say // Interface modules export say, say-implementor; // Substrate libraries use format-out; use dylan; end library say; // Protocol interface define module say create say; end module say; // Implementor interface define module say-implementor use say, export: all; use format-out, export: all; end module say-implementor; // Implementation module define module say-implementation use say; use dylan; end module say-implementation; The ``say`` implementation file ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The ``say`` implementation file: ``say.dylan``. .. code-block:: dylan Module: say-implementation define open generic say (object :: ) => (); The ``say`` LID file ~~~~~~~~~~~~~~~~~~~~ The LID file: ``say.lid``. .. code-block:: dylan library: say files: say-library say The ``time`` library -------------------- The ``time`` library is a client of the ``sixty-unit`` and ``say`` libraries, and it will serve as a substrate library for the rest of our application. Like the previous two libraries, it comprises a library file and an implementation file; we also show the corresponding LID file. The ``time-library`` file ~~~~~~~~~~~~~~~~~~~~~~~~~ The ``time-library`` file: ``time-library.dylan``. .. code-block:: dylan Module: dylan-user // Library definition define library time // Interface module export time; // Substrate libraries use sixty-unit; use say; use dylan; end library time; // Interface module define module time // Classes create