Hello World

You have just downloaded Open Dylan and installed it in /opt/opendylan. So how do you write the canonical Hello World app? This example assumes the bash shell is used. You may need to adjust for your local shell.

$ export PATH=/opt/opendylan/bin:$PATH
$ deft new application --simple hello-world
$ cd hello-world
$ deft build --all
...lots of output...
$ _build/bin/hello-world
Hello, world!

Ta da! Now a quick review of the steps with a little bit of explanation.

First you must set PATH so that the deft and dylan-compiler executables will be found. ./_build/bin is where dylan-compiler puts the executables it builds.

Note

Some of these differ on Windows, so please be sure to read Notes for Windows Users if you are on Windows.

deft new application --simple hello-world creates a directory named “hello-world”, and several files. The --simple flag says to skip generating a test suite library and instead of a separate hello-world library and hello-world-app executable library to just make one hello-world executable library.

  1. hello-world.lid lists the files in the project. The order in which the files are listed here determines the order in which the code in them is loaded. The library definition file should always be first.

  2. library.dylan contains the library and module definitions. These can be extended as your project grows in complexity. Note that the library and modules are defined in the pre-defined dylan-user module.

  3. hello-world.dylan contains the main program code. Note that this code is defined in the hello-world module of the hello-world library.

  4. The registry directory is how dylan-compiler locates each used library. deft generates this directory for you. See Using Source Registries for details on the registry format.

  5. dylan-package.json describes the new “hello-world” package. This is where you can specify dependencies, the package location, etc. See the deft documentation for more on this. Note that the existence of this file turns the “hello-world” directory into a deft workspace.

The first time you build your project all used libraries are built, all the way down to the dylan library itself. Subsequent builds only need to recompile hello-world itself and are therefore much faster.

The compiler places its output in the _build directory in the current working directory. This includes the libraries and executables that it builds. You can run the executable from this location, as noted above.