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: Sun, 09 Aug 2015 13:42:51 +0200 Organization: Informatimago Message-ID: <87fv3shemc.fsf@kuiper.lan.informatimago.com> References: <871tfdjqjx.fsf@mbork.pl> <55C69537.7020904@yandex.ru> <87bnehi9mn.fsf@kuiper.lan.informatimago.com> <87mvy0hi4t.fsf@kuiper.lan.informatimago.com> 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 1439120727 25550 80.91.229.3 (9 Aug 2015 11:45:27 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 9 Aug 2015 11:45:27 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Aug 09 13:45:23 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 1ZOP2Y-0007d2-AA for geh-help-gnu-emacs@m.gmane.org; Sun, 09 Aug 2015 13:45:22 +0200 Original-Received: from localhost ([::1]:54939 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZOP2X-0002RI-2U for geh-help-gnu-emacs@m.gmane.org; Sun, 09 Aug 2015 07:45:21 -0400 Original-Path: usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 129 Original-X-Trace: individual.net 7fwYwqHrcotKqnLHGYY/UAokjk0X2PzbXy6SQ2rORPI2NUhFmd Cancel-Lock: sha1:NjE0Y2NhMTI2YThhYzA4ZTQ5ODljZjM5MmI1ODhiNDMxM2RjYzQ3Ng== sha1:lZNH42a8wpAq/wilI6fpU0RkwLM= 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:214107 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:106391 Archived-At: Marcin Borkowski writes: > On 2015-08-09, at 12:26, Pascal J. Bourguignon wrote: > >> Marcin Borkowski writes: >> >>> On 2015-08-09, at 02:33, Pascal J. Bourguignon wrote: >>> >>>> Marcin Borkowski writes: >>>> >>>>> OK, but this seems a bit awkward, especially for my second example, >>>>> which would then become >>>>> >>>>> (list (list #'function argument) ...) >>>> >>>> `((,(function f) ,(gen 42))) >>> >>> What do you mean by `gen'? My Emacs (25.0.50.1) doesn't have such >>> a function. >> >> Why do I mean by f? > > OK, but (AFAIUC) in the above form `function' gets evaluated (so that > the symbol `f' -- the function name -- ends up in the list), and then > Emacs tries to /evaluate/ the form `(gen 42)'. This probably fooled me > (again). Do I get it right that you wanted to show how to generate the > argument dynamically and not put a constant in the whole expression? Right! I thought it would be obvious, because I misread what you wanted to do when you wrote: > (setq custom-format '((format-field-one 4) ...))? I thought you wanted to generate a field formater function created by the expression: (format-field-one 4). But now I'm reading: > (defun format-field-one (record width) > (format (format "%%%ds" width) (cdr (assoc 'field-one record)))) > > I want to be able to include in my custom "format" things like > > (format-field-one 4) and I realize that (format-field-one 4) is meaningless. I'm sorry, I'm often misled when people say there's a problem when there is no problem: (defun format-field-one (record width) (format (format "%%%ds" width) (cdr (assoc 'field-one record)))) (setq custom-format '((format-field-one 4))) (let ((record-list '(((field-one . 33)) ((field-one . 42))))) (mapcar (lambda (record) (mapcar (lambda (field-specifier) (apply (car field-specifier) record (cdr field-specifier))) custom-format)) record-list)) --> ((" 33") (" 42")) And as seen in the rest of the discussion, writting it as: (setq custom-format `((,#'format-field-one 4))) --> ((format-field-one 4)) instead of: (setq custom-format '((format-field-one 4))) --> ((format-field-one 4)) wouldn't change anything in emacs lisp. On the other hand, you could write a function to generate a closure to format fields: (setf lexical-binding t) ; why isn't it the default already? (defun generate-field-formatter (width) (let ((format-control (format "%%%ds" width))) (lambda (record) (format format-control (cdr (assoc 'field-one record)))))) (setq custom-format `(,(generate-field-formatter 4))) ;; --> ((closure ((format-control . "%4s") (width . 4) t) (record) (format format-control (cdr (assoc (quote field-one) record))))) (let ((record-list '(((field-one . 33)) ((field-one . 42))))) (mapcar (lambda (record) (mapcar (lambda (field-formatter) (funcall field-formatter record)) custom-format)) record-list)) ;; --> ((" 33") (" 42")) and here, I discover an horrible bug in emacs-version "24.3.1": (byte-compile 'generate-field-formatter) ;; --> #[(width) "\301\302\"\210\303\207" [width format "%%%ds" #[(record) "\302\303\304 \"A\"\207" [format-control record format assoc field-one] 5]] 3] (setq custom-format `(,(generate-field-formatter 4))) ;; --> (#[(record) "\302\303\304 \"A\"\207" [format-control record format assoc field-one] 5]) (let ((record-list '(((field-one . 33)) ((field-one . 42))))) (mapcar (lambda (record) (mapcar (lambda (field-formatter) (funcall field-formatter record)) custom-format)) record-list)) Debugger entered--Lisp error: (void-variable format-control) -- __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