DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH
 

(guile.info.gz) Hook Reference

Info Catalog (guile.info.gz) Hook Example (guile.info.gz) Hooks (guile.info.gz) C Hooks
 
 24.6.2 Hook Reference
 ---------------------
 
 When you create a hook with `make-hook', you must specify the arity of
 the procedures which can be added to the hook.  If the arity is not
 given explicitly as an argument to `make-hook', it defaults to zero.
 All procedures of a given hook must have the same arity, and when the
 procedures are invoked using `run-hook', the number of arguments passed
 must match the arity specified at hook creation time.
 
    The order in which procedures are added to a hook matters.  If the
 third parameter to `add-hook!' is omitted or is equal to `#f', the
 procedure is added in front of the procedures which might already be on
 that hook, otherwise the procedure is added at the end.  The procedures
 are always called from the front to the end of the list when they are
 invoked via `run-hook'.
 
    The ordering of the list of procedures returned by `hook->list'
 matches the order in which those procedures would be called if the hook
 was run using `run-hook'.
 
    Note that the C functions in the following entries are for handling
 "Scheme-level" hooks in C.  There are also "C-level" hooks which have
 their own interface ( C Hooks).
 
  -- Scheme Procedure: make-hook [n_args]
  -- C Function: scm_make_hook (n_args)
      Create a hook for storing procedure of arity N_ARGS.  N_ARGS
      defaults to zero.  The returned value is a hook object to be used
      with the other hook procedures.
 
  -- Scheme Procedure: hook? x
  -- C Function: scm_hook_p (x)
      Return `#t' if X is a hook, `#f' otherwise.
 
  -- Scheme Procedure: hook-empty? hook
  -- C Function: scm_hook_empty_p (hook)
      Return `#t' if HOOK is an empty hook, `#f' otherwise.
 
  -- Scheme Procedure: add-hook! hook proc [append_p]
  -- C Function: scm_add_hook_x (hook, proc, append_p)
      Add the procedure PROC to the hook HOOK. The procedure is added to
      the end if APPEND_P is true, otherwise it is added to the front.
      The return value of this procedure is not specified.
 
  -- Scheme Procedure: remove-hook! hook proc
  -- C Function: scm_remove_hook_x (hook, proc)
      Remove the procedure PROC from the hook HOOK.  The return value of
      this procedure is not specified.
 
  -- Scheme Procedure: reset-hook! hook
  -- C Function: scm_reset_hook_x (hook)
      Remove all procedures from the hook HOOK.  The return value of
      this procedure is not specified.
 
  -- Scheme Procedure: hook->list hook
  -- C Function: scm_hook_to_list (hook)
      Convert the procedure list of HOOK to a list.
 
  -- Scheme Procedure: run-hook hook . args
  -- C Function: scm_run_hook (hook, args)
      Apply all procedures from the hook HOOK to the arguments ARGS.
      The order of the procedure application is first to last.  The
      return value of this procedure is not specified.
 
    If, in C code, you are certain that you have a hook object and well
 formed argument list for that hook, you can also use `scm_c_run_hook',
 which is identical to `scm_run_hook' but does no type checking.
 
  -- C Function: void scm_c_run_hook (SCM hook, SCM args)
      The same as `scm_run_hook' but without any type checking to confirm
      that HOOK is actually a hook object and that ARGS is a well-formed
      list matching the arity of the hook.
 
    For C code, `SCM_HOOKP' is a faster alternative to `scm_hook_p':
 
  -- C Macro: int SCM_HOOKP (x)
      Return 1 if X is a Scheme-level hook, 0 otherwise.
 
 24.6.3 Handling Scheme-level hooks from C code
 ----------------------------------------------
 
 Here is an example of how to handle Scheme-level hooks from C code using
 the above functions.
 
      if (SCM_NFALSEP (scm_hook_p (obj)))
        /* handle Scheme-level hook using C functions */
        scm_reset_hook_x (obj);
      else
        /* do something else (obj is not a hook) */
 
Info Catalog (guile.info.gz) Hook Example (guile.info.gz) Hooks (guile.info.gz) C Hooks
automatically generated byinfo2html