next | previous | forward | backward | up | top | index | toc | Macaulay2 website
Macaulay2Doc > The Macaulay2 language > using hooks > addHook

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



For an explanation and examples of hooks see using hooks.


../../../../../../../Macaulay2/m2/methods.m2:591:52-600: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)

See also

Ways to use addHook :

For the programmer

The object addHook is a method function with options.