# addHook -- add a hook function to an object for later processing

## Synopsis

• Usage:
• Inputs:
• key, or ,
• hook,
• store,
• Optional inputs:
• Strategy => , default value null, specifies the name for the hook
• Consequences:
• the function hook is added to the (possibly absent) hash table of hooks, which is either stored in the mutable hash table store or under the youngest Type T listed in the method key key. In the latter case, the hash table is either stored in T.Hooks#key if T is mutable, or in T.cache.Hooks#key otherwise. If no appropriate object is found, or if key is a Symbol, then the hook is stored under the hash table GlobalHookStore

## Description

For an explanation and examples of hooks see using hooks.

## Code

/usr/share/Macaulay2/Core/methods.m2:533:52-542:32: --source code:
addHook(MutableHashTable, Thing, Function) := opts -> (store, key, hook) -> (
-- this is the hashtable of Hooks for a specific key, which stores HookAlgorithms and HookPriority
if not store#?key then store#key = new MutableHashTable from {
HookAlgorithms => new MutableHashTable, -- a mutable hash table "strategy key" => "strategy code"
HookPriority   => new MutableList},     -- a mutable list of strategy keys, in order
store = store#key;
ind := #store.HookPriority; -- index to add the hook in the list; TODO: use Priority to insert in the middle?
alg := if opts.Strategy =!= null then opts.Strategy else ind;
store.HookPriority#ind = alg;
store.HookAlgorithms#alg = hook)