unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: help-gnu-emacs@gnu.org
Subject: Re: Problem when run-hook-with-args with closure
Date: Fri, 19 Dec 2014 09:11:45 -0500	[thread overview]
Message-ID: <jwvoaqzn326.fsf-monnier+gmane.emacs.help@gnu.org> (raw)
In-Reply-To: CAJnfWeFmL-xcp54vvz4R40-DZ199trj05_6UgH=7eS1tnz+wEw@mail.gmail.com

>   (setq foo
>         (lambda (y)
>           (message "x+y=%d" (+ x y)))))
> (run-hook-with-args 'foo 1)

Hooks should contain *lists* of functions.  The fact that they can also
just contain a function is an old backward compatibility hack: better
not rely on it.

So, if you do it right, you won't hit the bug:

     (setq foo
           (list (lambda (y)
                   (message "x+y=%d" (+ x y))))))
   (run-hook-with-args 'foo 1)

Or better yet:

     (add-hook 'foo
               (lambda (y)
                   (message "x+y=%d" (+ x y))))))
   (run-hook-with-args 'foo 1)


-- Stefan




  parent reply	other threads:[~2014-12-19 14:11 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-18  6:57 Problem when run-hook-with-args with closure Zhongwei Yao
2014-12-19  9:09 ` Michael Heerdegen
2014-12-19  9:56   ` Zhongwei Yao
2014-12-19 11:13     ` Michael Heerdegen
2014-12-19  9:10 ` Michael Heerdegen
2014-12-19 14:11 ` Stefan Monnier [this message]
2014-12-22 11:20   ` Zhongwei Yao
2014-12-22 19:07     ` incremental search for "OK " matches "OK" followed by ^M for CR !? ISHIKAWA,Chiaki
2014-12-22 19:10       ` Drew Adams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvoaqzn326.fsf-monnier+gmane.emacs.help@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).