Next Previous Up Top Contents Index

4 Creating and Using Projects

4.6 The project start function

The New Project wizard always adds a start function to the end of the last file in the project.

The Dylan language does not require that a program define an explicit start function, such as main in C or Java. However, when you are debugging or interacting, Functional Developer finds it useful to know what you consider to be your program's start function. It allows the name of your start function to be recorded in its project information. By default, this name will be main, and corresponds to the main function that the New Project creates by default in the project-name.dylan file for all new projects. However, you are free to change the name if you like--there is nothing special about it.

The project-name.dylan file for all new projects will contain a definition of main and a call to it. Projects that include template code will contain this definition of main:

define method main () => ()
end method main;

Projects that do not include template code will contain this definition:

define method main () => ()
  // Your program starts here...
end method main;

For both kinds of project, the project-name.dylan file will end with this expression:


The name of the Start Function is one of the project settings you can change in the Project > Settings... dialog. It appears on the Debug page in the Start Function section. The default name is main, but you can change it to any valid Dylan name you like. If you do so, make sure to replace the call to main with a call to your new start function. The source file is not updated automatically.

Note that you can make the wizard use a different start function name in new project files by changing the default setting in the Advanced Project Settings dialog. Click Advanced... on the second wizard page to produce the dialog. In this case, the generated project code will call the correct new name without requiring you to make a change by hand.

The debugger uses the start function name to know where to pause a program that you start up in interaction mode with Application > Interact or the Interact () toolbar button, or in debugging mode with Application > Debug. When you start a program either way, the debugger allows the program to execute normally, but sets a breakpoint on the start function so that interaction or debugging begins at a point where the entire program has already been initialized.

If no start function is nominated for a project, the program pauses precisely before it exits but after everything in it has executed. This is usually what we want for a DLL, but not for an application.

Note: To be sure that you can access all the definitions in your application when you start it up in interaction mode, the call to main must come after all the definitions in the project. Typically, this means the call must be the last expression in the last file listed in the project. Otherwise, the application will be paused before all its definitions have been initialized, and interactions involving its definitions could behave in unexpected ways. See "Application and library initialization" on page 55 for more information on this topic.

Getting Started with Functional Developer - 31 MAR 2000

Next Previous Up Top Contents Index