Providing a Starting Point: runtime_entry/1

The application developer must specify what is to happen when the program is started up. This is done by defining the predicate runtime_entry/1. When the runtime system is run, the goal (A) is invoked. When that goal terminates, either by succeeding or by failing, the runtime system terminates.

     runtime_entry(start) (A)

Similarly, it is possible to specify what is to be done on an abort. An abort happens when a call is made either to the built-in predicate abort/0 or to the C routine QP_action(QP_ABORT). (By default, a call of QP_action(QP_ABORT) happens when a user types ^C-- see sap-rge-iha). At this point, the current computation is abandoned and the program is restarted with the goal (B).

     runtime_entry(abort) (B)

Effectively this replaces the original call to runtime_entry(start), so that when this call succeeds or fails, the runtime system terminates For example (C) will obviously loop indefinitely until you interrupt it with a ^C. At that point it will abort, and since the goal runtime_entry(abort) will fail, the program will terminate.

If you were to add the clause (D) you would make the program impervious to ^C interrupts and quite hard to terminate.

     runtime_entry(start) :- go. (C)
     go :- go.
     runtime_entry(abort) :- go. (D)

For this reason, it is recommended that you not write your code as (E) as this will cause your program to restart on ^C or errors.

Users of the module system should ensure that the predicate runtime_entry/1 is defined in the module user, that is, not inside any user-defined module. You may use a clause of the form (F) in a module-file to do this. (see ref-mod).

     runtime_entry(_):- ... (E)
     user:(runtime_entry(...):-...) (F)