For Development HEAD DRAFTSearch (procedure/syntax/module):

Next: , Previous: , Up: Library modules - Gauche extensions   [Contents][Index]

9.13 gauche.hook - Hooks

Module: gauche.hook

Provides a hook object, which manages a list of closures to be called at certain time.

This API of hooks are upper-compatible of Guile’s, with the following extensions.

  • Based on Gauche’s object system. Most APIs are methods so you can extend the hook features.
  • Hook object itself is applicable. You don’t need to use run-hook.
  • The method to remove a procedure from a hook is called delete-hook!, for consistency with SRFI-1 and others. remove-hook! is defined as an alias of delete-hook! for compatibility with Guile.

If you’re writing portable code, SRFI-173 provides the basic hook functionality (see srfi.173 - Hooks (srfi)).

Class: <hook>

{gauche.hook} A hook class, which keeps a list of procedures to be called at once.

The object-apply method is defined on <hook> class, so you can "apply" a hook object as if it were a procedure—which causes all the registered procedure to be invoked.

Function: make-hook :optional (arity 0)

{gauche.hook} Creates a new hook object with given arity, which should be a non-negative integer.

Function: hook? obj

{gauche.hook} Returns true if obj is a hook object.

Function: hook-empty? hook

{gauche.hook} Returns true if hook’s procedure list is empty.

Method: add-hook! (hook <hook>) proc :optional (append? #f)

{gauche.hook} Adds a procedure proc to hook. If append? is given and true, proc is added at the end of the list. Otherwise, proc is added at the front of the list. The proc has to be called with the arity given at the make-hook.

Method: delete-hook! (hook <hook>) proc
Method: remove-hook! (hook <hook>) proc

{gauche.hook} Removes proc from the procedure list of hook. Remove-hook! is an alias of delete-hook! just for compatibility with Guile.

Method: reset-hook! (hook <hook>)

{gauche.hook} Empties hook’s procedure list.

Method: hook->list (hook <hook>)

{gauche.hook} Returns a copy of hook’s procedure list.

Method: run-hook (hook <hook>) arg …

{gauche.hook} Calls hook’s procedures in order, with arguments arg …. The number of arguments must match the arity given at make-hook.

Next: , Previous: , Up: Library modules - Gauche extensions   [Contents][Index]

For Development HEAD DRAFTSearch (procedure/syntax/module):