guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Hook change hook?


From: Neil Jerram
Subject: Hook change hook?
Date: 15 Feb 2002 16:42:54 +0000
User-agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7

When working with hooks, I often find that I have to wrap access to
the hook rather than making the hook available directly, because I
need to do something extra whenever something is added or removed from
that hook.

For example:

(define trace-hook (make-hook))

(define-public (add-trace-hook! proc)
  (add-hook! trace-hook proc)
  (if (not (hook-empty? trace-hook))
      (debug-enable 'trace)))

(define-public (remove-trace-hook! proc)
  (add-hook! trace-hook proc)
  (if (hook-empty? trace-hook)
      (debug-disable 'trace)))

Suppose instead that a hook could have an observer associated with it,
which would be called whenever the hook was changed.  Then one could
expose the hook directly, and not require the user to use unusual
procedures to change it:

(define-public trace-hook (make-hook))

(define (trace-observer proc action)
  ((if (hook-empty? trace-hook)
       debug-disable
       debug-enable) 'trace))

(set-hook-observer trace-hook trace-observer)

[Although unused in this example, PROC would be the procedure that was
just added or removed, and ACTION would be a keyword, one of
`#:appended', `#:prepended' and `#:removed'.]

This strikes me as much nicer.  Would it be good to add this to Guile?

        Neil




reply via email to

[Prev in Thread] Current Thread [Next in Thread]