Please note that the content of this book primarily consists of articles
available from Wikipedia or other free sources online. In computer
programming, a callback is a reference to executable code, or a piece of
executable code, that is passed as an argument to other code. This
allows a lower-level software layer to call a subroutine defined in a
higher-level layer. Callbacks have a wide variety of uses. For example,
imagine a function that reads a configuration file and associates values
with options. If the options are identified by a hash, then writing the
function so that it takes a callback makes it more flexible: its user
can choose whatever hashing algorithm is desired and the function will
continue to work, since it uses the callback to turn option names into
hashes; thus, callbacks allow the user of a function to fine-tune it at
runtime. Another use is in error signaling. A Unix program, for example,
might not want to terminate immediately when it receives SIGTERM; to
make sure things get taken care of, it would register the cleanup
function as a callback. Callbacks may also be used to control whether a
function acts or not: Xlib allows custom predicates to be specified to
determine whether a program wishes to handle an event.