[Top][All Lists]

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

Re: Hook vs. list of procedures

From: Mikael Djurfeldt
Subject: Re: Hook vs. list of procedures
Date: Mon, 9 Jan 2017 13:39:33 +0100

Can I just add this:

First, as Andy already hinted, it's not how a data type is implemented but the operations in its API which defines it. A list does not map directly to a hook. A hook can be implemented as a list, but that is not important.

An example of a hook is before-print-hook which is used in (ice-9 history) and which can be used, for example, to support a communication protocol when running Guile in an IDE-like environment in Emacs.

If we had a naive use of lists as hooks, the correct way to extend it would be something like:

(set! before-print-hook (cons my-action before-print-hook))

but one could be tempted to do:

(set! before-print-hook (list my-action))

which would erase anything else added there or, even worse,

(define before-print-hook ...)

which would not affect the real before-print-hook since a new binding in the local module would be created.

(add-hook! before-print-hook my-action)

doesn't tempt you that way.

Also, with the current hook API, hooks are first-class citizens, which they would not be with a naive list implementation. Not sure that matters much, though.

On Mon, Jan 9, 2017 at 12:03 AM, Andy Wingo <address@hidden> wrote:
On Thu 15 Dec 2016 11:48, Jan Synáček <address@hidden> writes:

> I've read about hooks in the manual recently and I don't understand
> why they are special. What is the difference between a hook and a
> plain list of procedures? Why do hooks have their own API?

Historical reasons I think.  Early Emacs inspired a number of Guile
extension points, and hooks are a thing there.  (Hooks are not just a
list of procedures -- they're a settable place as well and a way of
running all of the procedures.)  Anyway I agree, nothing to shout about,
and probably something the manual should mention less prominently.


reply via email to

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