From mboxrd@z Thu Jan 1 00:00:00 1970 From: Oleh Krehel Subject: Re: Why does evaluating a piece of Elisp code seemingly not expand a macro? Date: Fri, 15 Jan 2016 11:57:17 +0100 Message-ID: <878u3rcdpu.fsf@gmail.com> References: <87a8o7duj6.fsf@mbork.pl> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:45720) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aK24K-0000yi-Lf for emacs-orgmode@gnu.org; Fri, 15 Jan 2016 05:57:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aK24G-0004cI-Lz for emacs-orgmode@gnu.org; Fri, 15 Jan 2016 05:57:24 -0500 Received: from mail-wm0-x236.google.com ([2a00:1450:400c:c09::236]:38193) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aK24G-0004cC-Ex for emacs-orgmode@gnu.org; Fri, 15 Jan 2016 05:57:20 -0500 Received: by mail-wm0-x236.google.com with SMTP id b14so18713807wmb.1 for ; Fri, 15 Jan 2016 02:57:19 -0800 (PST) In-Reply-To: <87a8o7duj6.fsf@mbork.pl> (Marcin Borkowski's message of "Fri, 15 Jan 2016 11:08:45 +0100") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Marcin Borkowski Cc: Org-Mode mailing list Marcin Borkowski writes: > Why? Macro-expand the defun to get: (defalias 'print-answer #'(lambda nil (message "The answer is %s." (forty-two)))) `lambda' is a macro that /quotes/ its body. Therefore, the body of `defun' is not evaluated or expanded when it's defined. You probably wanted something like this instead: (macroexpand-all '(lambda nil (message "The answer is %s." (forty-two)))) ;; => ;; (function ;; (lambda nil ;; (message ;; "The answer is %s." ;; 42))) Which could be wrapped in a new macro: (defmacro defun-1 (name arglist &optional docstring &rest body) (unless (stringp docstring) (setq body (if body (cons docstring body) docstring)) (setq docstring nil)) (list 'defun name arglist docstring (macroexpand-all body))) The above seems to work, at least superficially: (symbol-function (defun-1 print-answer () (message "The answer is %s." (forty-two)))) ;; => ;; (lambda nil ;; (message ;; "The answer is %s." ;; 42)) By the way, it might be more appropriate to ask similar questions on help-gnu-emacs@gnu.org. Oleh