Gwydion Dylan Demo Programs

These demos live in mindy/src/demos subdirectories. Note that in addition to the foo.dylan file pointed to, there is also a foo-exports.dylan which sets up the module namespace and a foo.lid which is used to tell d2c what to compile. Although with the exception of hello-world these demos are ordered alphabetically rather than by complexity, this is a quasi-tutorial in that there are various nuggets of wisdom scattered throughout.

If you have run mk-build-tree then there will be makefiles in the demo build directories which will compile the demos. We don't go into too much detail here about how to build these demos, see the documentation for mindy and d2c


This is the canonical "hello, world" demo. Type
  mindycomp -lhello-world hello-world-exports.dylan
  mindycomp -lhello-world hello-world.dylan
  mindy -f hello-world-exports.dbc -f hello-world.dbc
to run it under mindy or:
  d2c hello-world.lid
to run it under d2c.


This program demonstrates buffered stream I/O by duplicating the UNIX (tm) "cat" utility. See also stream-demo for more basic usage. Usage is typical for a unix program. It may be invoked either with a set of files on the command line:
  mindy -f cat-exports.dbc -f cat.dbc file1 file2 ....
or with no arguments, in which case it reads from "standard input". You may also specify special filename "-" which will refer to the standard input.

On most Unix systems you should be able to make it into an executable script by concatenating cat-exports.dbc and cat.dbc into say mindy-cat, prepending the the line

  #DYLANDIR/bin/mindy -f
and adding "execute" to the file's protection. Note that DYLANDIR must be substituted by you.

You could then simply type:

  mindy-cat file1 file2 ....
You must, of course, remember to specify the DYLANDIR environment variable so that it points to directories containing all of the relevant libraries. (This demo uses only "dylan" and "streams", but the "html2txt" demo also uses "collection-extensions".)


Slightly more sophisticated than hello-world, this demo makes use of the random library.


This program demonstrates the diff module of the Collection-extensions library. It mimics the UNIX (tm) "diff" utility.


  mindy -f diff-lib.dbc file1 file2

diff-lib.dbc is created by the Makegen makefile by contantenating diff-exports.dbc and diff.dbc. Limitations: Diff the stand-alone utility is meant purely as a demo. It doesn't support any of the options that a real diff utility does. It accepts input only as files; it won't read from standard input. The output format of our demo is slightly different from the standard Unix diff.

You must, of course, remember to specify the DYLANDIR environment variable so that it points to directories containing all of the relevant libraries. (This demo uses "dylan", "streams", "format", and "collection-extensions") The build procedure is similar to


The "html2txt" program is a filter which converts text in WWWs "HyperText Markup Language" into simple formatted text. Although it is a complete and useful application, it is included in this distribution primarily as a demonstration of a "real" (albeit small) Dylan (tm) program. Note that this demo only understands HTML 2.0.

Usage is similar to "cat" above, except that it does not support the "-" argument. You may therefore set of files on the command line or use standard input by specifying no command line arguments

  mindy -f html2txt-lib.dbc file1.html file2.html ....
  mindy -f cat-lib.dbc file1.html file2.html | mindy -f html2txt-lib.dbc
At present, "html2txt" accepts no command line switches, although the behavior may be changed by changing several constant declarations towards the top of the source file.

A useful test case for this program is this file (demos.html).

The basic translation strategy used by html2txt is to scan the file line by line, looking for HTML "tags" and accumulating text that lies between any two tags. For each tag type, there is a set of routines (stored in tables) which define the appropriate actions for starting and ending the "environment" defined by the tag and for dumping the collected text from within that environment as formatted text. A basic control loop in "process-HTML" is responsible for calling the appropriate tag actions. This routine may be called recusively by some of the tag actions.

The "interface" between adjacent environments is handled via the "blank" parameter which is passed around extensively. This variable states whether a blank line has just been printed. Thus environments which believe that they must be preceded or followed by a blank line can determine whetehr they must do anything about it, and we lessen the risk that multiple routines will emit blank lines when we only want a maximum of one.

The primary advantage of this organization is that it allows the specialized actions for a single tag to be grouped together, and allows new tags to be cleanly added. It benefits greatly from Dylan's ability to create anonymous methods and manipulate them as first class data objects, as well as from the rich set of available collection types.


This is the same program, only now with a spiffy graphical interface.

If you get the error message 'font "-adobe-courier-medium-r-normal--12*" doesn't exist', edit html2txt.dylan. Find the lines that define "normal-font" and "bold-font" and substitute a font your machine does have. Alternately, go down a few lines further and delete the "font: normal-font" and "font: bold-font" clauses.


A fairly minimal demo of creating one library (fact) and having another library (library-demo) use it. In the library-demo.lid note the use of Unit-Prefix: to prevent the creation of C identifiers with hyphens in them and in fact.lid the use of Unique-ID-Base: to make sure any exported classes have unique IDs (in this case there are none.)

Under Mindy, you can run this as the other demos:

  mindy -f library-demo-lib.dbc
Note however that library-demo-lib.dbc does not include the Fact library. Instead this is demand-loaded by searching on DYLANPATH for fact-lib.dbc (preferrably) or fact.dbc. Sometimes you can get in trouble if the -lib.dbc file doesn't appear in DYLANPATH before some other file that happens to use the unsuffixed name. Under d2c, all used libraries are statically linked into the executable, and you just type:


This is a quick and dirty imitation of Microsoft's Minesweeper game. It has a few improvements--it can do much of the tedious work for you! For various reasons, initializing the game board takes forever, but play is reasonably quick once everything's set up.


A simple use of streams for both file and terminal I/O.

[ Gwydion home page | mail to gwydion-group ]