help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to quote a list of functions?


From: Pascal J. Bourguignon
Subject: Re: How to quote a list of functions?
Date: Wed, 19 Aug 2015 03:54:00 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

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

> Emanuel Berg <embe8573@student.uu.se> writes:
>
>> Nonetheless, I always want to do things the right
>> way so I'll change my code. If I find anything apart
>> from the three cases I've brought to the attention
>> of this list, I'll mention those as well.
>
> First catch:
>
>     (call-interactively #'w3m)
>
> as
>
>     (call-interactively FUNCTION &optional RECORD-FLAG
>     KEYS)
>
>     Call FUNCTION, providing args according to its
>     interactive calling specs.

You should consider more closely my examples with cl-flet.
Compare:

    (cl-flet ((w3m () (interactive) (message "doh!")))
      (call-interactively #'w3m))

with:

    (cl-flet ((w3m () (interactive) (message "doh!")))
      (call-interactively 'w3m))


Also, in the case of Common Lisp, #'w3m would return a function object.
Therefore if you later redefine that function, ie. if you change the
fbinding of that name, the function object you saved will still be the
old function.  If you saved the name, then the name would now designate
the new function.

This is  a distinction that is lost on emacs lisp, and I would consider
that to be a bug.

    (defun f ()  'old)
    (defvar saved)
    (setf saved #'f)
    (funcall saved)            ; --> old
    (defun f ()  'new)
    (funcall saved)            ; --> old in Common Lisp, new in emacs lisp.


    (defun f ()  'old)
    (defvar saved)
    (setf saved (symbol-function 'f))
    (funcall saved)            ; --> old
    (defun f ()  'new)
    (funcall saved)            ; --> old  in both.


    (defun f ()  'old)
    (defvar saved)
    (setf saved (quote f))
    (funcall saved)            ; --> old
    (defun f ()  'new)
    (funcall saved)            ; --> new  in both.



    (cl-flet ((f () 'out))
      (setf saved #'f))
    (funcall saved)            ; --> out
    (cl-flet ((f () 'out))
       (cl-flet ((f () 'in))
         (setf saved #'f))
       (funcall saved))        ; --> in
    (funcall saved)            ; --> in


Clearly, the behavior of function in emacs lisp is inconsistent, between
its use with a global function and with a local lexical function
(closure).



But the point here is that when you compare (symbol-function 'f),
(function f) and (quote f) for the purpose of saving a reference to a
function for future calling,  you must know whether you save the
function object (or closure) or whether you save the symbol designating
the function, because if you redefine that function (the fbinding of
that symbol), then the saved function object won't change, but the
function referenced by the saved symbol will.   And again, function will
demonstrate inconsistent behavior depending on whether you applied it on
a global function or a local lexical function.


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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]