unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* Hook vs. list of procedures
@ 2016-12-15 10:48 Jan Synáček
  2017-01-08 23:03 ` Andy Wingo
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Synáček @ 2016-12-15 10:48 UTC (permalink / raw)
  To: guile-devel

Hi,

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?

Cheers,
-- 
Jan Synáček



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Hook vs. list of procedures
  2016-12-15 10:48 Hook vs. list of procedures Jan Synáček
@ 2017-01-08 23:03 ` Andy Wingo
  2017-01-09 12:39   ` Mikael Djurfeldt
  0 siblings, 1 reply; 3+ messages in thread
From: Andy Wingo @ 2017-01-08 23:03 UTC (permalink / raw)
  To: Jan Synáček; +Cc: guile-devel

On Thu 15 Dec 2016 11:48, Jan Synáček <jan.synacek@gmail.com> 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.

Andy



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Hook vs. list of procedures
  2017-01-08 23:03 ` Andy Wingo
@ 2017-01-09 12:39   ` Mikael Djurfeldt
  0 siblings, 0 replies; 3+ messages in thread
From: Mikael Djurfeldt @ 2017-01-09 12:39 UTC (permalink / raw)
  To: Andy Wingo; +Cc: guile-devel

[-- Attachment #1: Type: text/plain, Size: 1888 bytes --]

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 <wingo@pobox.com> wrote:

> On Thu 15 Dec 2016 11:48, Jan Synáček <jan.synacek@gmail.com> 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.
>
> Andy
>
>

[-- Attachment #2: Type: text/html, Size: 2603 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-01-09 12:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-15 10:48 Hook vs. list of procedures Jan Synáček
2017-01-08 23:03 ` Andy Wingo
2017-01-09 12:39   ` Mikael Djurfeldt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).