Each compiled application has database workspaces available to it where you can store interpreted predicates and data. You may wish to write some code which detects whether your application is being run for the first time and, if so, loads one or more databases with some initial state. Or, you may wish to use API32 or another application to create databases that will be used by your application.
You should review carefully the discussions about saving and restoring databases and about workspaces, worlds, and partitions, particularly if your application is multi-threaded.
A simple example of a start-up procedure that loads clauses into the database of a compiled program follows:
main :- key(startup, _), % succeeds only if the key 'startup' is in the database [myInterpFile1,myInterpFile2], % here we have 2 files with interpreted code consulted recordz(startup, 1, _), % just record something under the key 'startup' fail. main :- runMyApplication. % ready to go
Some points to remember relevant to application initialization:
- Startup code for the application can specify the maximum number of threads and environment parameters.
- The environment file for the application can be used to specify a default database.
- When a database is created, it has only a single world. (It is named 'main').
- When a database is created, it has only a single partition. (It is designated as partition 0).
- When a thread is initialized, it is set to use workspace 0.
- Operator directives may be defined within compiled code or you may use the op/3 predicate at startup. Operators are not stored in databases, so if you initialize these at runtime you will need to do this every time the application is started.