From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nicolas Richard Newsgroups: gmane.emacs.help Subject: Re: Macro Expansion Inconsistency Date: Wed, 17 Dec 2014 15:21:18 +0100 Message-ID: <5491915E.7080103@yahoo.fr> References: <87r3vyegmt.fsf@yahoo.fr> 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 1418826136 11012 80.91.229.3 (17 Dec 2014 14:22:16 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 17 Dec 2014 14:22:16 +0000 (UTC) Cc: help-gnu-emacs To: Alexander Shukaev , John Mastro Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Dec 17 15:22:09 2014 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 1Y1FUN-0003GO-3r for geh-help-gnu-emacs@m.gmane.org; Wed, 17 Dec 2014 15:22:07 +0100 Original-Received: from localhost ([::1]:49762 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y1FUM-0003bx-Bi for geh-help-gnu-emacs@m.gmane.org; Wed, 17 Dec 2014 09:22:06 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40633) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y1FU6-0003br-IB for help-gnu-emacs@gnu.org; Wed, 17 Dec 2014 09:21:56 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y1FU0-0002ZK-DD for help-gnu-emacs@gnu.org; Wed, 17 Dec 2014 09:21:50 -0500 Original-Received: from mxin.ulb.ac.be ([164.15.128.112]:8521) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y1FU0-0002ZC-7D for help-gnu-emacs@gnu.org; Wed, 17 Dec 2014 09:21:44 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AsYBANuQkVSkD4Xx/2dsb2JhbAANTYc2sDEBAQEBAQEGlVqCTQKBNQEBAQEBhQoBAQMBIw8BRQEFCwsODAIFFgsCAgkDAgECAUUGAQwBBwEBF4d8AQy9S3CBa44aAYYgAQEBAQEBAQMBAQEBAQEBARqBIYRfgiqBYIVoB4JogUEBBJZ4gQuEYogbgziED4MxAQEB Original-Received: from mathsrv4.ulb.ac.be (HELO [172.19.79.241]) ([164.15.133.241]) by smtp.ulb.ac.be with ESMTP; 17 Dec 2014 15:21:41 +0100 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 In-Reply-To: X-TagToolbar-Keys: D20141217152118656 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 164.15.128.112 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:101635 Archived-At: Le 17/12/2014 15:03, Alexander Shukaev a écrit : > Thank you very much, John and Nicolas. I think I finally understand > how macros expand in Emacs Lisp better now. I'm sure it's not a > coincidence that you both came up with almost identical solutions. It > suggests that the style of returning forms for evaluation from macro > is probably the best way to go in most cases when `let' is involved. I hadn't seen John's answer. His solution is better than mine because the (put ...) forms should indeed be included in the progn. (otherwise they get executed at expansion time, and I think that'll not be good if the code is byte-compiled.) > As a final exam for myself, considering what I've learned, I've implemented a collective definition macro as well: > > (defmacro bm-define-flags > (name index character foreground &rest ...) > (let ((name `,name) > (index `,index) > (character `,character) > (foreground `,foreground) > (... `(,@...)) I think the above bindings are unnecessary. > (body '())) > (while name > (push `(bm-define-flag ,name ,index ,character ,foreground) body) > (setq name (pop ...) > index (pop ...) > character (pop ...) > foreground (pop ...))) > `(progn ,@body))) Looks ok to me (but I'm not experienced). > (put 'bm-define-flags 'lisp-indent-function 'defun) I don't think that's useful for bm-define-flags. Btw you can also use a (declare ...) form in your macro definition to achieve this goal. -- Nicolas.