all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* ~`symbol-function' to get code as list even when byte-compiled?
@ 2015-05-25  2:52 Emanuel Berg
  2015-05-25  2:58 ` Barry Margolin
  2015-05-25  3:10 ` Pascal J. Bourguignon
  0 siblings, 2 replies; 19+ messages in thread
From: Emanuel Berg @ 2015-05-25  2:52 UTC (permalink / raw)
  To: help-gnu-emacs

(re-search-forward "^Question")

Here is some interesting code. What's interesting is:
when this code executes, it changes itself, i.e.
the code changes the code!

But it isn't a macro which is a program that produces
a new program based on its own logic and non-evaluated
input data.

On the contrary, here we deal all with ordinary
functions (defuns) where one changes the other.
Does that always happen? No - only when it is needed!

See the entire code here [1]. Go there if you want to
see this in execution as it probably is based on some
other functions as well. The below code is for display
purposes ONLY!

Question: this is all working thanks to
`symbol-function' which is used to get the code of the
function as data, so it can be examined and
manipulated. However, if I byte-compile the code
(which I always do), `symbol-function' doesn't return
a lambda function which is also a list, but instead
just a function #[...] which isn't a list. So then it
doesn't work!

I was able to do a workaround with `load-file' in
.emacs to get all the functions in the file in
evaluated form. But, can I do that specifically for
a named function, *or*, can I extract the code in list
format somehow even if compiled?

(symbol-function jump)

(defun enable-jump (jump)
  (add-hook 'w3m-display-hook jump)
  (let*((code                  (symbol-function jump))
        (remove-code           `(remove-hook 'w3m-display-hook (quote ,jump)))
        (remove-code-index     2)
        (current-code          (nth remove-code-index code)) )
    (unless (equal current-code remove-code)
      (push remove-code (nthcdr remove-code-index code)) )))

(defun web-search ()
  (interactive)
  (let ((search (get-search-string "Google")))
    (unless (empty-string-p search)
      (w3m-new-tab (format "Google: %s" search))
      (w3m-search w3m-search-default-engine search) ))
  (enable-jump 'number-one-jump) )

(defun number-one-jump (&optional not-used) ; Google, Youtube
  (when (re-search-forward "^ 1." (point-max) t)
    (recenter-top-bottom 0)
    (w3m-next-anchor) ))

[1] http://user.it.uu.se/~embe8573/conf/emacs-init/w3m/w3m-unisearch.el

-- 
underground experts united
http://user.it.uu.se/~embe8573


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

* Re: ~`symbol-function' to get code as list even when byte-compiled?
  2015-05-25  2:52 ~`symbol-function' to get code as list even when byte-compiled? Emanuel Berg
@ 2015-05-25  2:58 ` Barry Margolin
  2015-05-25 17:16   ` Emanuel Berg
  2015-05-25  3:10 ` Pascal J. Bourguignon
  1 sibling, 1 reply; 19+ messages in thread
From: Barry Margolin @ 2015-05-25  2:58 UTC (permalink / raw)
  To: help-gnu-emacs

In article <877frxid14.fsf@debian.uxu>,
 Emanuel Berg <embe8573@student.uu.se> wrote:

> (re-search-forward "^Question")
> 
> Here is some interesting code. What's interesting is:
> when this code executes, it changes itself, i.e.
> the code changes the code!
> 
> But it isn't a macro which is a program that produces
> a new program based on its own logic and non-evaluated
> input data.
> 
> On the contrary, here we deal all with ordinary
> functions (defuns) where one changes the other.
> Does that always happen? No - only when it is needed!
> 
> See the entire code here [1]. Go there if you want to
> see this in execution as it probably is based on some
> other functions as well. The below code is for display
> purposes ONLY!
> 
> Question: this is all working thanks to
> `symbol-function' which is used to get the code of the
> function as data, so it can be examined and
> manipulated. However, if I byte-compile the code
> (which I always do), `symbol-function' doesn't return
> a lambda function which is also a list, but instead
> just a function #[...] which isn't a list. So then it
> doesn't work!
> 
> I was able to do a workaround with `load-file' in
> .emacs to get all the functions in the file in
> evaluated form. But, can I do that specifically for
> a named function, *or*, can I extract the code in list
> format somehow even if compiled?

You can probably prevent it from being compiled, maybe something like:

(setf (symbol-function 'number-one-jump)
     '(lambda (&optional not-used) ...))

But can't you do something equivalent by using advice instead of 
self-modifying code?

> 
> (symbol-function jump)
> 
> (defun enable-jump (jump)
>   (add-hook 'w3m-display-hook jump)
>   (let*((code                  (symbol-function jump))
>         (remove-code           `(remove-hook 'w3m-display-hook (quote ,jump)))
>         (remove-code-index     2)
>         (current-code          (nth remove-code-index code)) )
>     (unless (equal current-code remove-code)
>       (push remove-code (nthcdr remove-code-index code)) )))
> 
> (defun web-search ()
>   (interactive)
>   (let ((search (get-search-string "Google")))
>     (unless (empty-string-p search)
>       (w3m-new-tab (format "Google: %s" search))
>       (w3m-search w3m-search-default-engine search) ))
>   (enable-jump 'number-one-jump) )
> 
> (defun number-one-jump (&optional not-used) ; Google, Youtube
>   (when (re-search-forward "^ 1." (point-max) t)
>     (recenter-top-bottom 0)
>     (w3m-next-anchor) ))
> 
> [1] http://user.it.uu.se/~embe8573/conf/emacs-init/w3m/w3m-unisearch.el

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***


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

* Re: ~`symbol-function' to get code as list even when byte-compiled?
  2015-05-25  2:52 ~`symbol-function' to get code as list even when byte-compiled? Emanuel Berg
  2015-05-25  2:58 ` Barry Margolin
@ 2015-05-25  3:10 ` Pascal J. Bourguignon
  2015-05-25 17:07   ` Emanuel Berg
  1 sibling, 1 reply; 19+ messages in thread
From: Pascal J. Bourguignon @ 2015-05-25  3:10 UTC (permalink / raw)
  To: help-gnu-emacs

Emanuel Berg <embe8573@student.uu.se> writes:

> (re-search-forward "^Question")
>
> Here is some interesting code. What's interesting is:
> when this code executes, it changes itself, i.e.
> the code changes the code!
>
> But it isn't a macro which is a program that produces
> a new program based on its own logic and non-evaluated
> input data.
>
> On the contrary, here we deal all with ordinary
> functions (defuns) where one changes the other.
> Does that always happen? No - only when it is needed!
>
> See the entire code here [1]. Go there if you want to
> see this in execution as it probably is based on some
> other functions as well. The below code is for display
> purposes ONLY!
>
> Question: this is all working thanks to
> `symbol-function' which is used to get the code of the
> function as data, so it can be examined and
> manipulated. However, if I byte-compile the code
> (which I always do), `symbol-function' doesn't return
> a lambda function which is also a list, but instead
> just a function #[...] which isn't a list. So then it
> doesn't work!

This is your hint.


> I was able to do a workaround with `load-file' in
> .emacs to get all the functions in the file in
> evaluated form. But, can I do that specifically for
> a named function, *or*, can I extract the code in list
> format somehow even if compiled?

No.

But since you should not do that anyways, it should not be a problem.

Variables have been invented for a purpose.



-- 
__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


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

* Re: ~`symbol-function' to get code as list even when byte-compiled?
  2015-05-25  3:10 ` Pascal J. Bourguignon
@ 2015-05-25 17:07   ` Emanuel Berg
  2015-05-25 17:18     ` Pascal J. Bourguignon
       [not found]     ` <mailman.3638.1432574334.904.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 19+ messages in thread
From: Emanuel Berg @ 2015-05-25 17:07 UTC (permalink / raw)
  To: help-gnu-emacs

"Pascal J. Bourguignon" <pjb@informatimago.com>
writes:

> Variables have been invented for a purpose.

...which is?

-- 
underground experts united
http://user.it.uu.se/~embe8573


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

* Re: ~`symbol-function' to get code as list even when byte-compiled?
  2015-05-25  2:58 ` Barry Margolin
@ 2015-05-25 17:16   ` Emanuel Berg
  2015-05-25 17:37     ` Pascal J. Bourguignon
  0 siblings, 1 reply; 19+ messages in thread
From: Emanuel Berg @ 2015-05-25 17:16 UTC (permalink / raw)
  To: help-gnu-emacs

Barry Margolin <barmar@alum.mit.edu> writes:

> You can probably prevent it from being compiled,
> maybe something like:
>
> (setf (symbol-function 'number-one-jump) '(lambda
> (&optional not-used) ...))

Yeah, but if I were to do special treatment, then
I might as well put

    (remove-hook 'w3m-display-hook 'number-one-jump)

in "number-one-jump" and have it compiled like
all others!

The reason for this idea, which I should have said in
the OP, is that I have many such jump functions, e.g.:

    (defun emacs-wiki-jump (&optional not-used)
      (if (search-forward "EmacsWiki" (point-max) t)
          (beginning-of-line) ))

    (defun urban-jump (&optional not-used)
      (when (search-forward "Top Definition" (point-max) t)
        (w3m-next-anchor)
        (recenter-top-bottom 0) ))

So instead of putting the corresponding remove-hook in
every one, this is what "enable-jump" does. Only it
doesn't work if the jump functions are compiled, which
didn't occurred to me when I got the idea and wrote
the code.

> But can't you do something equivalent by using
> advice instead of self-modifying code?

Possibly - how would that work?

-- 
underground experts united
http://user.it.uu.se/~embe8573


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

* Re: ~`symbol-function' to get code as list even when byte-compiled?
  2015-05-25 17:07   ` Emanuel Berg
@ 2015-05-25 17:18     ` Pascal J. Bourguignon
       [not found]     ` <mailman.3638.1432574334.904.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 19+ messages in thread
From: Pascal J. Bourguignon @ 2015-05-25 17:18 UTC (permalink / raw)
  To: help-gnu-emacs

Emanuel Berg <embe8573@student.uu.se> writes:

> "Pascal J. Bourguignon" <pjb@informatimago.com>
> writes:
>
>> Variables have been invented for a purpose.
>
> ...which is?

To store state.  

Don't store state in the code, use the code to act on state stored in
variables!

-- 
__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




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

* Re: ~`symbol-function' to get code as list even when byte-compiled?
  2015-05-25 17:16   ` Emanuel Berg
@ 2015-05-25 17:37     ` Pascal J. Bourguignon
  0 siblings, 0 replies; 19+ messages in thread
From: Pascal J. Bourguignon @ 2015-05-25 17:37 UTC (permalink / raw)
  To: help-gnu-emacs

Emanuel Berg <embe8573@student.uu.se> writes:

> Barry Margolin <barmar@alum.mit.edu> writes:
>
>> You can probably prevent it from being compiled,
>> maybe something like:
>>
>> (setf (symbol-function 'number-one-jump) '(lambda
>> (&optional not-used) ...))
>
> Yeah, but if I were to do special treatment, then
> I might as well put
>
>     (remove-hook 'w3m-display-hook 'number-one-jump)
>
> in "number-one-jump" and have it compiled like
> all others!
>
> The reason for this idea, which I should have said in
> the OP, is that I have many such jump functions, e.g.:
>
>     (defun emacs-wiki-jump (&optional not-used)
>       (if (search-forward "EmacsWiki" (point-max) t)
>           (beginning-of-line) ))
>
>     (defun urban-jump (&optional not-used)
>       (when (search-forward "Top Definition" (point-max) t)
>         (w3m-next-anchor)
>         (recenter-top-bottom 0) ))
>
> So instead of putting the corresponding remove-hook in
> every one, this is what "enable-jump" does. Only it
> doesn't work if the jump functions are compiled, which
> didn't occurred to me when I got the idea and wrote
> the code.
>
>> But can't you do something equivalent by using
>> advice instead of self-modifying code?
>
> Possibly - how would that work?

You could do something like this:

(defun split-body (body)
  (loop
    with docstring = nil
    with declarations = '()
    for forms on body
    while (and forms
               (cond
                 ((stringp (first forms)) (not docstring))
                 ((listp (first forms))
                  (member (first (first forms)) '(interactive declare)))
                 (t nil)))
    do (if (stringp (first forms))
           (setf docstring (first forms))
           (push (first forms) declarations))
    finally (return (list docstring (nreverse declarations) forms))))


(defmacro define-jump (name lamda-list &rest body)
  (destructuring-bind (docstring declarations body) (split-body body)
    `(progn
       (setf (get ',name 'jump-enabled) (list t nil))
       (defun ,name ,lambda-list
        ,@(when docstring (list docstring))
        ,@declarations
        (when (second (get ',name 'jump-enabled))
          (remove-hook 'w3m-display-hook (quote ,name))
          (setf (second (get ',name 'jump-enabled)) nil))
        ,@body))))

(defun enable-jump (name)
  (unless (first (get name 'jump-enabled))
    (error "%S is not a defined jump." name))
  (setf (second (get name 'jump-enabled)) t)
  (add-hook 'w3m-display-hook name))

(define-jump number-one-jump (&optional not-used) ; Google, Youtube
  (when (re-search-forward "^ 1." (point-max) t)
    (recenter-top-bottom 0)
    (w3m-next-anchor)))


(defun web-search ()
  (interactive)
  (let ((search (get-search-string "Google")))
    (unless (empty-string-p search)
      (w3m-new-tab (format "Google: %s" search))
      (w3m-search w3m-search-default-engine search) ))
  (enable-jump 'number-one-jump))




-- 
__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




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

* Re: ~`symbol-function' to get code as list even when byte-compiled?
       [not found]     ` <mailman.3638.1432574334.904.help-gnu-emacs@gnu.org>
@ 2015-05-25 17:41       ` Emanuel Berg
  2015-05-25 17:48         ` Pascal J. Bourguignon
       [not found]         ` <mailman.3640.1432576116.904.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 19+ messages in thread
From: Emanuel Berg @ 2015-05-25 17:41 UTC (permalink / raw)
  To: help-gnu-emacs

"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.

-- 
underground experts united
http://user.it.uu.se/~embe8573


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

* Re: ~`symbol-function' to get code as list even when byte-compiled?
  2015-05-25 17:41       ` Emanuel Berg
@ 2015-05-25 17:48         ` Pascal J. Bourguignon
       [not found]         ` <mailman.3640.1432576116.904.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 19+ messages in thread
From: Pascal J. Bourguignon @ 2015-05-25 17:48 UTC (permalink / raw)
  To: help-gnu-emacs

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




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

* Re: ~`symbol-function' to get code as list even when byte-compiled?
       [not found]         ` <mailman.3640.1432576116.904.help-gnu-emacs@gnu.org>
@ 2015-05-26  0:01           ` Emanuel Berg
  2015-05-26  0:12             ` Emanuel Berg
  0 siblings, 1 reply; 19+ messages in thread
From: Emanuel Berg @ 2015-05-26  0:01 UTC (permalink / raw)
  To: help-gnu-emacs

"Pascal J. Bourguignon" <pjb@informatimago.com>
writes:

> 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.

That's exactly right! I knew this could be done
without macros. Only, I had to change "gensym" into
`cl-gensym' and add the "unused" argument to the
lambda as with `w3m-display-hook', "each function is
called with a url string as the argument".
The byte-compiler then said

    Warning: Unused lexical argument `unused'

so I made "use" of it to keep the compiler quiet.

;;;; -*- lexical-binding:t -*-

(defun add-one-shot-hook (hook fun)
  (let ((name (cl-gensym)))
    (setf (symbol-function name)
          (lambda (&rest unused)
            (progn
              unused
              (remove-hook hook name)
              (funcall fun) )))
    (add-hook hook name) ))

I guess I like it fine - so far...

-- 
underground experts united
http://user.it.uu.se/~embe8573


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

* Re: ~`symbol-function' to get code as list even when byte-compiled?
  2015-05-26  0:01           ` Emanuel Berg
@ 2015-05-26  0:12             ` Emanuel Berg
  2015-05-26 20:34               ` Stefan Monnier
  0 siblings, 1 reply; 19+ messages in thread
From: Emanuel Berg @ 2015-05-26  0:12 UTC (permalink / raw)
  To: help-gnu-emacs

Emanuel Berg <embe8573@student.uu.se> writes:

> so I made "use" of it to keep the compiler quiet.

Perhaps this is a better (safer) way to have it in but
still out of action. I never contemplated the Boolean
logic of Elisp but I take it it is short-circuited.
Of course, the byte-compiler's warnings aren't there so
you can come up with ways to code them away, but what
the...

(defun add-one-shot-hook (hook fun)
  (let ((name (cl-gensym)))
    (setf (symbol-function name)
          (lambda (&rest unused)
            (when (or t unused)
              (remove-hook hook name)
              (funcall fun) )))
    (add-hook hook name) ))

-- 
underground experts united
http://user.it.uu.se/~embe8573


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

* Re: ~`symbol-function' to get code as list even when byte-compiled?
  2015-05-26  0:12             ` Emanuel Berg
@ 2015-05-26 20:34               ` Stefan Monnier
  2015-05-26 23:02                 ` Emanuel Berg
  0 siblings, 1 reply; 19+ messages in thread
From: Stefan Monnier @ 2015-05-26 20:34 UTC (permalink / raw)
  To: help-gnu-emacs

> Perhaps this is a better (safer) way to have it in but
> still out of action. I never contemplated the Boolean

Why have it out of action?  The Right Thing to do is to pass it along to fun:

   (defun add-one-shot-hook (hook fun)
     (let ((name (cl-gensym)))
       (setf (symbol-function name)
             (lambda (&rest args)
               (remove-hook hook name)
               (apply fun args)))
       (add-hook hook name)))


-- Stefan


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

* Re: ~`symbol-function' to get code as list even when byte-compiled?
  2015-05-26 20:34               ` Stefan Monnier
@ 2015-05-26 23:02                 ` Emanuel Berg
  2015-05-27  1:07                   ` Stefan Monnier
  0 siblings, 1 reply; 19+ messages in thread
From: Emanuel Berg @ 2015-05-26 23:02 UTC (permalink / raw)
  To: help-gnu-emacs

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> Perhaps this is a better (safer) way to have it in
>> but still out of action.
>
> Why have it out of action? The Right Thing to do is to
> pass it along to fun:
>
>    (defun add-one-shot-hook (hook fun) (let ((name
> (cl-gensym))) (setf (symbol-function name) (lambda
> (&rest args) (remove-hook hook name) (apply fun
> args))) (add-hook hook name)))

When I did this by putting the "payload" functions
directly into the w3m hook that required them to all
have one parameter, as w3m executed all them hook
functions with the URL passed as (the
single) argument.

However now with this solution when there is a lambda
around the functions the lambda can deal with the
argument, so I removed the parameters from all the
payloads. E.g., number-one-jump now looks like this:

    (defun number-one-jump () ; Google, Youtube
      (when (re-search-forward "^ 1." (point-max) t)
        (recenter-top-bottom 0)
        (w3m-next-anchor) ))

So correct me if I'm wrong, but if I used `apply' with
the argument as you suggest, wouldn't that lead to an
error, namely wrong-number-of-arguments? On the other
hand, if I then were to add those parameters again to
the payloads, wouldn't I have the byte-compiler
complain even more (once for each function) that
*they* don't use the argument?

-- 
underground experts united
http://user.it.uu.se/~embe8573


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

* Re: ~`symbol-function' to get code as list even when byte-compiled?
  2015-05-26 23:02                 ` Emanuel Berg
@ 2015-05-27  1:07                   ` Stefan Monnier
  2015-05-27  1:31                     ` Emanuel Berg
  0 siblings, 1 reply; 19+ messages in thread
From: Stefan Monnier @ 2015-05-27  1:07 UTC (permalink / raw)
  To: help-gnu-emacs

> When I did this by putting the "payload" functions
> directly into the w3m hook that required them to all
> have one parameter, as w3m executed all them hook

Of course.  That's how the hook is defined.

> However now with this solution when there is a lambda
> around the functions the lambda can deal with the
> argument, so I removed the parameters from all the
> payloads.

That presumes that this argument is never useful, i.e. that the
designers of this hook were mistaken.

> On the other hand, if I then were to add those parameters again to the
> payloads, wouldn't I have the byte-compiler complain even more (once
> for each function) that *they* don't use the argument?

Each function can decide to use the argument or not individually, which
is how things should be.  You can tell the compiler that the argument is
locally unused by putting an underscore as its first char.  E.g.

    (defun my-payload (&optional _display)
      (message "See, I don't use `display'!"))


-- Stefan


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

* Re: ~`symbol-function' to get code as list even when byte-compiled?
  2015-05-27  1:07                   ` Stefan Monnier
@ 2015-05-27  1:31                     ` Emanuel Berg
  2015-05-27  1:55                       ` Stefan Monnier
  0 siblings, 1 reply; 19+ messages in thread
From: Emanuel Berg @ 2015-05-27  1:31 UTC (permalink / raw)
  To: help-gnu-emacs

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> However now with this solution when there is
>> a lambda around the functions the lambda can deal
>> with the argument, so I removed the parameters from
>> all the payloads.
>
> That presumes that this argument is never useful,
> i.e. that the designers of this hook were mistaken.

It only affects those functions that are added with
this new method.

> Each function can decide to use the argument or not
> individually, which is how things should be. You can
> tell the compiler that the argument is locally
> unused by putting an underscore as its first char.

I'll use that for the lambda instead: that way the
functions remain unaware which was the idea all along.
If the interface isn't general enough I don't have
problem having as many specific interfaces as needed -
I think that is even a good thing, while having the
functions "must" look a certain way that doesn't
relate to what they do but in what context they
perhaps (?) will execute - a bad thing.

-- 
underground experts united
http://user.it.uu.se/~embe8573


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

* Re: ~`symbol-function' to get code as list even when byte-compiled?
  2015-05-27  1:31                     ` Emanuel Berg
@ 2015-05-27  1:55                       ` Stefan Monnier
  2015-05-27  2:20                         ` Emanuel Berg
  0 siblings, 1 reply; 19+ messages in thread
From: Stefan Monnier @ 2015-05-27  1:55 UTC (permalink / raw)
  To: help-gnu-emacs

> I'll use that for the lambda instead: that way the
> functions remain unaware which was the idea all along.

That's fine, but then you should name it "add-one-shot-hook" since that
name implies it can be used with any hook and any function placed on
such a hook, rather than only for those functions which want to ignore
the arguments provided by the hook's caller.


        Stefan


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

* Re: ~`symbol-function' to get code as list even when byte-compiled?
  2015-05-27  1:55                       ` Stefan Monnier
@ 2015-05-27  2:20                         ` Emanuel Berg
  2015-05-27  2:31                           ` Stefan Monnier
  0 siblings, 1 reply; 19+ messages in thread
From: Emanuel Berg @ 2015-05-27  2:20 UTC (permalink / raw)
  To: help-gnu-emacs

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> I'll use that for the lambda instead: that way the
>> functions remain unaware which was the idea
>> all along.
>
> That's fine, but then you should name it
> "add-one-shot-hook" since that name implies it can
> be used with any hook and any function placed on
> such a hook, rather than only for those functions
> which want to ignore the arguments provided by the
> hook's caller.

You mean, I should NOT name it that, but
"add-one-shot-hook-args-ignored" or something like
that. OK.

-- 
underground experts united
http://user.it.uu.se/~embe8573


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

* Re: ~`symbol-function' to get code as list even when byte-compiled?
  2015-05-27  2:20                         ` Emanuel Berg
@ 2015-05-27  2:31                           ` Stefan Monnier
  2015-05-27 23:49                             ` Emanuel Berg
  0 siblings, 1 reply; 19+ messages in thread
From: Stefan Monnier @ 2015-05-27  2:31 UTC (permalink / raw)
  To: help-gnu-emacs

> You mean, I should NOT name it that, but
> "add-one-shot-hook-args-ignored" or something like
> that. OK.

Right.  Tho my recommendation is to always pass those args to your
payloads; and if those payloads are meant to be used "anywhere" and
don't care about their args, then give them an arglist of (&rest _).


        Stefan


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

* Re: ~`symbol-function' to get code as list even when byte-compiled?
  2015-05-27  2:31                           ` Stefan Monnier
@ 2015-05-27 23:49                             ` Emanuel Berg
  0 siblings, 0 replies; 19+ messages in thread
From: Emanuel Berg @ 2015-05-27 23:49 UTC (permalink / raw)
  To: help-gnu-emacs

Stefan Monnier <monnier@iro.umontreal.ca> writes:

> Right. Tho my recommendation is to always pass those
> args to your payloads; and if those payloads are
> meant to be used "anywhere" and don't care about
> their args, then give them an arglist of (&rest _).

If the functions don't need special treatment I'm OK
with the extra glue to make it all work.

But, if the functions do need special treatment, ever
so slight, I'm not OK with the glue because then
I might as well go all the way and explicitly remove
the selfsame functions from the hook, and that will
not require any glue at all.

I'm OK with both solutions but not a hybrid one
encompassing parts of both.

On the different side altogether, if there is
a (semi-)official solution to the base problem (i.e.,
add a one shot function to a hook), I will use it and
(obviously) then comply with the interface.

-- 
underground experts united
http://user.it.uu.se/~embe8573


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

end of thread, other threads:[~2015-05-27 23:49 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-25  2:52 ~`symbol-function' to get code as list even when byte-compiled? Emanuel Berg
2015-05-25  2:58 ` Barry Margolin
2015-05-25 17:16   ` Emanuel Berg
2015-05-25 17:37     ` Pascal J. Bourguignon
2015-05-25  3:10 ` Pascal J. Bourguignon
2015-05-25 17:07   ` Emanuel Berg
2015-05-25 17:18     ` Pascal J. Bourguignon
     [not found]     ` <mailman.3638.1432574334.904.help-gnu-emacs@gnu.org>
2015-05-25 17:41       ` Emanuel Berg
2015-05-25 17:48         ` Pascal J. Bourguignon
     [not found]         ` <mailman.3640.1432576116.904.help-gnu-emacs@gnu.org>
2015-05-26  0:01           ` Emanuel Berg
2015-05-26  0:12             ` Emanuel Berg
2015-05-26 20:34               ` Stefan Monnier
2015-05-26 23:02                 ` Emanuel Berg
2015-05-27  1:07                   ` Stefan Monnier
2015-05-27  1:31                     ` Emanuel Berg
2015-05-27  1:55                       ` Stefan Monnier
2015-05-27  2:20                         ` Emanuel Berg
2015-05-27  2:31                           ` Stefan Monnier
2015-05-27 23:49                             ` Emanuel Berg

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.