This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: add-hook!


Mikael Djurfeldt <mdj@nada.kth.se> writes:

> The goal for Guile is to support good programming style, not to save
> typing.  `add-hook!' sounds like an operation which adds something to
> a hook.  You don't expect it to return anything.

Supporting good programming style is different from mandating good
programming style by making some constructs more awkward to use.  It's
not that unusual to have a hook-registration procedure return a handle
with which the proc can be removed.

> 
> Currently, you can do:
> 
>   (define foo (lambda (win) (display win)))
>   (add-hook! window-close-hook foo)
> 
>   (remove-hook! foo)
> 
> To me, this actually looks better than the example above since it is
> more readable.

Agreed, but that's not the point.  In:

(define my-hook-remove-handle 
    (add-hook! window-close-hook 
       (lambda (win) (display win))))

my-hook-remove-handle has different semantics from the `foo' symbol --
it *so* *happens* that it is the procedure, but the API can specify that 
it's simply something that can be used as an argument to remove-hook!
instead of the procedure.  You can look at it as an implementation
detail that it is really the procedure.

Greg