Macaulay2 » Documentation
Packages » Macaulay2Doc > The Macaulay2 language > using hooks > runHooks
next | previous | forward | backward | up | index | toc

runHooks -- run the hook functions stored in an object

Synopsis

Description

Each function hook in the hash table of hooks associated to key is called with args as its argument or sequence of arguments. The optional argument Strategy can be used to specify which hook should be run. See addHook for where the hooks are stored.

Any other optional argument for runHooks that matches any key in options hook will be passed on to hook. All other options are ignored.

For further explanation and examples of hooks see using hooks.

Code

../../../../../Macaulay2/m2/option.m2:37:19-40:29: --source code:
  (opts,f) -> args -> (
       -- Common code for functions created with >> to separate options from arguments.
       -- uncurry(f, (new OptionTable from toList select(args, i -> instance(i,Option)), select(args, i -> not instance(i,Option))))
       uncurry(f, override (,args))
       )
  )
| symbol  class            value                                                    location of symbol
| ------  -----            -----                                                    ------------------                             
| f       FunctionClosure  FunctionClosure[../../../../../Macaulay2/m2/methods.m2.  ../../../../../Macaulay2/m2/option.m2:37:8-37:9
| opts    Boolean          true                                                     ../../../../../Macaulay2/m2/option.m2:37:3-37:7
| -- function f:
| ../../../../../Macaulay2/m2/methods.m2:632:57-648:94: --source code:
| runHooks(MutableHashTable, Thing, Thing) := true >> opts -> (store, key, args) -> (
|     store = if store#?key then store#key else (
|         if debugLevel > 1 then printerr("runHooks: no hooks installed for ", toString key); return );
|     alg := if opts.?Strategy then opts.Strategy;
|     type := class alg;
|     -- if Strategy is not given, run through all available hooks
|     if alg === null then scan(reverse store.HookPriority, alg -> (
|             result := runHook(store.HookAlgorithms#alg, key, alg, args, opts ++ { Strategy => alg });
|             if not instance(result, Nothing) then break result)) else
|     -- if Strategy is given, and it is among the known strategies, run only that hook
|     if store.HookAlgorithms#?alg  then runHook(store.HookAlgorithms#alg,  key, alg,  args, opts) else
|     -- otherwise, if the class of alg is a known strategy, run only that hook
|     -- TODO: implement reverse lookup to find strategy installed under ancestors of type?
|     if store.HookAlgorithms#?type then runHook(store.HookAlgorithms#type, key, type, args, opts) else
|     -- otherwise, give an error with the list of possible strategies
|     error("unrecognized Strategy => '", toString alg, "' for ", toString key, newline,
|         "  available strategies are: ", demark_", " \\ toExternalString \ new List from store.HookPriority))

See also

Ways to use runHooks :

For the programmer

The object runHooks is a method function with options.