all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Kevin Rodgers <ihs_4664@yahoo.com>
Subject: Re: the hand that feeds you
Date: Thu, 27 Jul 2006 17:43:27 -0600	[thread overview]
Message-ID: <eabj2f$7s1$1@sea.gmane.org> (raw)
In-Reply-To: <pco8xme1z6d.fsf@shuttle.math.ntnu.no>

Harald Hanche-Olsen wrote:
> + Andreas Seik <andreas_neu@gmxpro.de>:
> 
> | Hello Newsgroup,
> |
> | i need code in a hook that is executed only once,
> | so i tested the following:
> |
> |
> | (defvar my-hook '())
> | (defun kill-myself ()
> |  (insert "only once")(remove-hook 'my-hook 'kill-myself))
> | (add-hook 'my-hook 'kill-myself)
> | (run-hooks 'my-hook);; i think it might crash here, but it does not
> | (run-hooks 'my-hook)
> |
> | it, seems to work, but i do not trust it.
> | is it not "biting the hand that feeds you"
> 
> It works, even in the presence of more hooks on the hook variable.
> But I agree it looks scary, and it seems to rely on the implementation
> of run-hooks and remove-hook:  In all likelihood, run-hooks will just
> cdr down the list, running the car of the rest each time.  And
> remove-hook will not modify the cons cell containing kill-myself as
> its car and the remaining list as its cdr, so all is well.
> 
> But it's bad coding style, because you must reason out all that to see
> why it works.  And it is conceivable, if unlikely, that the
> implementation one of these functions will change so that it no longer
> works.  Better then, to let kill-myself really to commit suicide,
> rather than just to remove itself from a hook:
> 
> (defun kill-myself ()
>   (insert "only once")
>   (defun kill-myself ()))

That is just as dependent on the implementation of defun as the original
is on the implementation of run-hooks and remove-hooks, isn't it?
Although I guess you could argue that it's only fragile with respect to
1 special form instead of 2 functions.

BTW, this is truly suicidal:

(defun kill-myself ()
   (insert "only once")
   (unintern 'kill-myself))

But maybe (fmakunbound 'kill-myself) or
(fset 'kill-myself (symbol-function 'ignore)) is good enough.  :-)

All I wanted was a Pepsi,
-- 
Kevin

  reply	other threads:[~2006-07-27 23:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-27 21:31 the hand that feeds you Andreas Seik
2006-07-27 22:05 ` Harald Hanche-Olsen
2006-07-27 23:43   ` Kevin Rodgers [this message]
     [not found]   ` <mailman.4562.1154043820.9609.help-gnu-emacs@gnu.org>
2006-07-28  9:12     ` Harald Hanche-Olsen
2006-07-28  6:50 ` wenbinye

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

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

  git send-email \
    --in-reply-to='eabj2f$7s1$1@sea.gmane.org' \
    --to=ihs_4664@yahoo.com \
    /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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.