From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Pascal J. Bourguignon" Newsgroups: gmane.emacs.help Subject: Re: How to quote a list of functions? Date: Wed, 19 Aug 2015 03:54:00 +0200 Organization: Informatimago Message-ID: <87zj1o82mf.fsf@kuiper.lan.informatimago.com> References: <871tfdjqjx.fsf@mbork.pl> <87zj1vddkz.fsf@kuiper.lan.informatimago.com> <87mvxug2us.fsf@nl106-137-147.student.uu.se> <87vbch1gb0.fsf@nl106-137-147.student.uu.se> <87wpwudby7.fsf@nl106-137-147.student.uu.se> <87zj1qbwxs.fsf@kuiper.lan.informatimago.com> <87r3n2btjl.fsf@kuiper.lan.informatimago.com> <87mvxqbooi.fsf@kuiper.lan.informatimago.com> <8737zhcsvo.fsf@nl106-137-147.student.uu.se> <87b6cce0-ebe6-400a-b6e9-957e79a66511@default> <87oai4yvcg.fsf@nl106-137-147.student.uu.se> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1439949329 32225 80.91.229.3 (19 Aug 2015 01:55:29 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 19 Aug 2015 01:55:29 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Aug 19 03:55:26 2015 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZRsb0-0006Z1-3t for geh-help-gnu-emacs@m.gmane.org; Wed, 19 Aug 2015 03:55:18 +0200 Original-Received: from localhost ([::1]:60265 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZRsaz-0005ic-Bh for geh-help-gnu-emacs@m.gmane.org; Tue, 18 Aug 2015 21:55:17 -0400 Original-Path: usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 99 Original-X-Trace: individual.net XKa2GO7i7ax1Ec+jGd3vaQ1lcOCZ7qP9S1K/uKysR7ortbZ9D+ Cancel-Lock: sha1:YTA3ODAwZTZhMjg1NDMyOTA3NWRjZjkxNDVlNTAwMDg0YjA5NDIwOA== sha1:cX4+wFWsBeYJiVRMSPGMZMyJNpc= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Original-Xref: usenet.stanford.edu gnu.emacs.help:214420 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:106703 Archived-At: Emanuel Berg writes: > Emanuel Berg 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