atexit

atexit — evaluates code before exiting a program.

Syntax

atexit (code)

		

Arguments

code

Code to be evaluated.

Returns

The result of evaluating code.

Description

This function gives a program an opportunity to evaluate specified code before it exits. The code should be protected from evaluation using the quote operator #.

Example

Running this program...

#!/usr/cogent/bin/gamma

// Program name: exiting.g
// Demonstrates the atexit() function.

atexit(#princ("Exiting now.\n"));
princ("Started running...\n");
princ("Still running.\n");
exit_program(7);
princ("You missed this part.\n");
		

...gives these results:

[sh]$ exiting.g
Started running...
Still running.
Exiting now.
[sh]$