onexit = ...
This field is provided by the program element, and allows you to specify a procedure to handle the event where the user attempts to close the ioL console window by clicking the window's close button.
If this field has no assigned code, ioL will respond to this event by terminating the ioL console; but this is not a graceful way to exit.
The preferred way to exit is for a program to terminate on its own terms. The ioL console then detects that the program's standard io streams are no longer active and the ioL console closes automatically.
An event field like onexit defines a procedure to be run when the event happens.
A procedure in ioL is simply a list of tags and data elements, which are evaluated (in order) to produce some result or behaviour. You can't create markup elements inside the event handling procedure itself, but you can use a push operation inside your procedure to add new markup elements to another location.
Since we didn't get to create this event field ourselves (the program element generates this field automatically when the program starts), we need to use a push operation to add our code handler to it.
Example
This doesn't do what we want:
<program.onexit <putln {An onexit event happened on the program element}>> <!INCORRECT!>
It doesn't work because of ioL's assignment precedence: ioL first tries to evaluate the putln tag to get a return value out of it, and then tries to assign the result of the evaluation. This means the putln instruction is executed immediately instead of stored in the event handler. It does not return a result, so nothing is stored in the program.onexit field.
Instead, we need to use a push operation. This assigns first and evaluates the code later in the context of the target field, which is what we want:
<program.onexit.clear> <! Not needed unless we've set other code previously. !> <program.onexit.push <putln {An onexit event happened on the program element}>>