From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Mikael Djurfeldt Newsgroups: gmane.lisp.guile.devel Subject: Re: Hook vs. list of procedures Date: Mon, 9 Jan 2017 13:39:33 +0100 Message-ID: References: <87k2a5b1e9.fsf@pobox.com> Reply-To: mikael@djurfeldt.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a113ee31aea900e0545a8a8a1 X-Trace: blaine.gmane.org 1483965597 940 195.159.176.226 (9 Jan 2017 12:39:57 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 9 Jan 2017 12:39:57 +0000 (UTC) Cc: guile-devel To: Andy Wingo Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Mon Jan 09 13:39:51 2017 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cQZEs-0007v6-W5 for guile-devel@m.gmane.org; Mon, 09 Jan 2017 13:39:51 +0100 Original-Received: from localhost ([::1]:39282 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cQZEx-00043M-10 for guile-devel@m.gmane.org; Mon, 09 Jan 2017 07:39:55 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47278) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cQZEf-000436-UN for guile-devel@gnu.org; Mon, 09 Jan 2017 07:39:39 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cQZEe-0005Hg-KS for guile-devel@gnu.org; Mon, 09 Jan 2017 07:39:37 -0500 Original-Received: from mail-io0-x242.google.com ([2607:f8b0:4001:c06::242]:35143) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cQZEe-0005Fi-Fb for guile-devel@gnu.org; Mon, 09 Jan 2017 07:39:36 -0500 Original-Received: by mail-io0-x242.google.com with SMTP id m98so6745504iod.2 for ; Mon, 09 Jan 2017 04:39:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:reply-to:sender:in-reply-to:references:from:date :message-id:subject:to:cc; bh=GYSP56QXcXjxZAMWXlN/fo4X6b7hDxFZHMAZp/yE9hc=; b=alN5EGEjCvorrIGK1Ul+CIekiKd3EfzUZUdy/Q/C8z6qPPBCp3PwFIPwCtWhhf0bec CV7WZo8QBzfLQorbPqpuWkM6+poGpBNVxYV85P9eeh/eLVMIDDEA3nv9rkiWgWSfeKof NV2JRkP1G9HKCRogqeJIPL/CIELEOw1+j9UL9hArPrEN0wOKFOy4TPdrFm1ecINhf/Bi A9SkiAjr9ym2BHHDLiK76hF671Rh7ilXJ0KOtNsAcjcYDbxsmYoKM9/IrLzqJgqN+bB3 /cBphwJUxGw7MAQy+2sk1u3ySoXbT8RIvvRCPR3pOvKgQ3wUjtaFhJ15aiOu3ArwUamk U0fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:reply-to:sender:in-reply-to :references:from:date:message-id:subject:to:cc; bh=GYSP56QXcXjxZAMWXlN/fo4X6b7hDxFZHMAZp/yE9hc=; b=TpschLOEc1MLBYahhRjPpeB4BZRBNaOr8TuwJl3JdR43QVGTiG8HbfM5eTKL7dwElV g80RR45v0+aZH5RWkcOWrCbsfmaKuwngd6dfsSx57jGzEHT+IndirSnI/ymHgHTPhrzA wYvfCiflamaJ1/BBEmz/FFe3G+/KRd5p77ToTfU21kzYkCcwdDwxAN4UN1a43aSEJFea jULcBhSh13F2yZLfwWvfxzbpWDtj+x0BgtWnz5t91Oc6Ga5JAKDjtK6Q216U8wpwVQjZ qgmssHIMO3FejmY5QG9g9IrdxZ5k+7l47GPT+VKPFDLhfJP9G8UZmZj7W2zSj0bDTXPA 5LAg== X-Gm-Message-State: AIkVDXL5kBqP9rRBvoSG/dBjljC9nD4AFlKaE3F5arCDbUzrTZWadx+HIYHtmwtzyqlPIRl8GeF46bNM446hbg== X-Received: by 10.107.10.156 with SMTP id 28mr61129610iok.18.1483965574318; Mon, 09 Jan 2017 04:39:34 -0800 (PST) Original-Received: by 10.64.58.9 with HTTP; Mon, 9 Jan 2017 04:39:33 -0800 (PST) In-Reply-To: <87k2a5b1e9.fsf@pobox.com> X-Google-Sender-Auth: wr8qjIJQeQWrZesy6_qckH_A3Q0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4001:c06::242 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: "guile-devel" Xref: news.gmane.org gmane.lisp.guile.devel:18841 Archived-At: --001a113ee31aea900e0545a8a8a1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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 wrote: > On Thu 15 Dec 2016 11:48, Jan Syn=C3=A1=C4=8Dek w= rites: > > > 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 > > --001a113ee31aea900e0545a8a8a1 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Can I just ad= d 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 i= s not important.

An example of a=20 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=20 Guile in an IDE-like environment in Emacs.

If we had a naive u= se 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 i= n the local module would be created.

(add-hook! before-print-h= ook 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 implementat= ion. Not sure that matters much, though.

On Mon, Jan 9, 2017 at 12:03 AM, Andy Wingo <<= a href=3D"mailto:wingo@pobox.com" target=3D"_blank">wingo@pobox.com>= wrote:
On Thu 15= Dec 2016 11:48, Jan Syn=C3=A1=C4=8Dek <jan.synacek@gmail.com> writes:

> I've read about hooks in the manual recently and I don't under= stand
> 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.=C2=A0 Early Emacs inspired a number of G= uile
extension points, and hooks are a thing there.=C2=A0 (Hooks are not just a<= br> list of procedures -- they're a settable place as well and a way of
running all of the procedures.)=C2=A0 Anyway I agree, nothing to shout abou= t,
and probably something the manual should mention less prominently.

Andy


--001a113ee31aea900e0545a8a8a1--