This section contains an example of a complete Dylan application that uses a generic factorial calculation routine to return the value of the factorial of 100. Two libraries are defined: the factorial library provides an implementation of the generic factorial routine, and the factorial-application library provides a method that calls the generic routine and returns the appropriate result.
File: fact.lid. LID file describing the components of the factorial library.
Library: factorial
Synopsis: Provides a naive implementation of the factorial
function
Keywords: factorial, integer, simple, recursive
Files: fact-def
fact
File: fact-def.dyl. Defines the factorial library and its one module.
Module: dylan-user define library factorial use dylan; export factorial; end; define module factorial export fact; end;
File: fact.dyl. Defines the method for calculating a factorial.
Module: factorial define generic fact(n); define method fact(n == 0) 1; end; define method fact(n) n * fact(n - 1); end;
File: app.lid. LID file describing the components of the factorial-application library.
Library: factorial-application
Synopsis: Computes factorial 100
Files: appdef
app
Start-Module: factorial-application
Start-Function: main
File: appdef.dyl. Defines the factorial-application library and its one module.
Module: dylan-user define library factorial-application use dylan; use factorial; end library; define module factorial-application use dylan; use factorial; end module;
File: app.dyl. Defines a routine that calls the factorial routine.
Module: factorial-application define method main (#rest ignore) fact(100); end method;
The following example demonstrates how files of foreign source code and resource files can be integrated into a Dylan library:
Library: app-with-foreign-code
Synopsis: Uses some C code and resources
Files: dylan-code
C-Source-Files: first.c
second.c
C-Header-Files: headers.h
RC-Files: extra-resources.rc