[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: ~`symbol-function' to get code as list even when byte-compiled?
From: |
Pascal J. Bourguignon |
Subject: |
Re: ~`symbol-function' to get code as list even when byte-compiled? |
Date: |
Mon, 25 May 2015 19:48:19 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) |
Emanuel Berg <embe8573@student.uu.se> writes:
> "Pascal J. Bourguignon" <pjb@informatimago.com>
> writes:
>
>> To store state.
>>
>> Don't store state in the code, use the code to act
>> on state stored in variables!
>
> The problem can be restated like this:
>
> A, B, ..., N are arbitrary functions.
>
> At some time they (in any constellation) will be
> included in a hook function list.
>
> However, each function should only be executed *once*
> and then immediately dropped from that hook.
>
> A, B, ..., and N don't know any of this, and in
> particular they don't know what hook they might be
> added to.
Then you can just write:
;;;; -*- mode:emacs-lisp;lexical-binding:t;coding:utf-8 -*-
(defun add-one-shot-meat (hook fun)
(let ((name (gensym)))
(setf (symbol-function name)
(lambda ()
(remove-hook hook name)
(funcall fun)))
(add-hook hook name)))
and use add-one-shot-meat instead of add-hook.
--
__Pascal Bourguignon__ http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk
- ~`symbol-function' to get code as list even when byte-compiled?, Emanuel Berg, 2015/05/24
- Re: ~`symbol-function' to get code as list even when byte-compiled?, Barry Margolin, 2015/05/24
- Re: ~`symbol-function' to get code as list even when byte-compiled?, Pascal J. Bourguignon, 2015/05/24
- Re: ~`symbol-function' to get code as list even when byte-compiled?, Emanuel Berg, 2015/05/25
- Re: ~`symbol-function' to get code as list even when byte-compiled?, Pascal J. Bourguignon, 2015/05/25
- Message not available
- Re: ~`symbol-function' to get code as list even when byte-compiled?, Emanuel Berg, 2015/05/25
- Re: ~`symbol-function' to get code as list even when byte-compiled?,
Pascal J. Bourguignon <=
- Message not available
- Re: ~`symbol-function' to get code as list even when byte-compiled?, Emanuel Berg, 2015/05/25
- Re: ~`symbol-function' to get code as list even when byte-compiled?, Emanuel Berg, 2015/05/25
- Re: ~`symbol-function' to get code as list even when byte-compiled?, Stefan Monnier, 2015/05/26
- Re: ~`symbol-function' to get code as list even when byte-compiled?, Emanuel Berg, 2015/05/26
- Re: ~`symbol-function' to get code as list even when byte-compiled?, Stefan Monnier, 2015/05/26
- Re: ~`symbol-function' to get code as list even when byte-compiled?, Emanuel Berg, 2015/05/26
- Re: ~`symbol-function' to get code as list even when byte-compiled?, Stefan Monnier, 2015/05/26
- Re: ~`symbol-function' to get code as list even when byte-compiled?, Emanuel Berg, 2015/05/26
- Re: ~`symbol-function' to get code as list even when byte-compiled?, Stefan Monnier, 2015/05/26
- Re: ~`symbol-function' to get code as list even when byte-compiled?, Emanuel Berg, 2015/05/27