From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: PJ Weisberg Newsgroups: gmane.emacs.devel Subject: Re: eval-when-compile Date: Fri, 27 Jul 2012 00:41:36 -0700 Message-ID: References: <871ujx94qo.fsf@Rainer.invalid> <871ujxd8in.fsf@kuiper.lan.informatimago.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: dough.gmane.org 1343374915 9368 80.91.229.3 (27 Jul 2012 07:41:55 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 27 Jul 2012 07:41:55 +0000 (UTC) Cc: emacs-devel@gnu.org To: "Pascal J. Bourguignon" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Jul 27 09:41:55 2012 Return-path: Envelope-to: ged-emacs-devel@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 1SufBK-0005oV-Ul for ged-emacs-devel@m.gmane.org; Fri, 27 Jul 2012 09:41:55 +0200 Original-Received: from localhost ([::1]:44296 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SufBK-0005AI-92 for ged-emacs-devel@m.gmane.org; Fri, 27 Jul 2012 03:41:54 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:41516) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SufBB-00059z-Bl for emacs-devel@gnu.org; Fri, 27 Jul 2012 03:41:51 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SufB5-0004wy-85 for emacs-devel@gnu.org; Fri, 27 Jul 2012 03:41:45 -0400 Original-Received: from mail-lb0-f169.google.com ([209.85.217.169]:40956) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SufB5-0004wt-0S for emacs-devel@gnu.org; Fri, 27 Jul 2012 03:41:39 -0400 Original-Received: by lbjn8 with SMTP id n8so2193513lbj.0 for ; Fri, 27 Jul 2012 00:41:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=peGfWz5xowrxJ+yDvxDIfcrW0Fs7HpBh40Sz1SPcDXo=; b=FEqTX319yB0pNGfXBqjGbZVr1hVtJVtGgglHBwMSujcs3AKDBMB6eJN4v78kUy56yI 4rITOrF3si5wmXWXfU2kMvIUGLpIS7X59dCTwcNQiqBCBT5DW95We6VLbcIDGrQc37kq gnlnGGM+iv+THAMNWrE1e/34K557JVBoBxFv4qY738Iztoduxe8dXiWw/scCuqamchK6 tJuyEUuKZfNZyGxeFe0KjGdXUQMUBI9BtP7VFR0wjXc9AecdzqMyUdQqf2FQm7yLqoLH +ps5OVfmVzDsJOO1YuweG38XvzJii7nyI+PGRkYnHREgzxFMP2EDqrgKSCsWOzGa0Ec0 +/pw== Original-Received: by 10.152.134.177 with SMTP id pl17mr1587259lab.37.1343374896995; Fri, 27 Jul 2012 00:41:36 -0700 (PDT) Original-Received: by 10.112.5.102 with HTTP; Fri, 27 Jul 2012 00:41:36 -0700 (PDT) In-Reply-To: <871ujxd8in.fsf@kuiper.lan.informatimago.com> X-Google-Sender-Auth: XayAqalFZAqpoH_yphSQB49Oyps X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.217.169 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:151901 Archived-At: On Thu, Jul 26, 2012 at 11:26 PM, Pascal J. Bourguignon wrote: > Achim Gratz writes: >> (eval-when-compile >> (if t >> (defvar unquoted-t "true") >> (defvar unquoted-nil "false"))) Try evaluating that block. It has side effects, of course, but the result is: 'unquoted-t That's just a symbol, sitting there all alone and not doing anything. There are no instructions to execute, so the byte compiler doesn't have anything to output. >> (eval-when-compile >> (if nil >> '(defvar quoted-t "true") >> '(defvar quoted-nil "false"))) That evaluates to: '(defvar quoted-nil "false") That's a list. Just a list, not a function call. Once again, nothing for the byte compiler to do. eval-when-compile isn't a macro; it results in a value, not code. >> (eval-when-compile >> (defmacro ewc-macro (&rest body) >> (if nil >> '(defvar macro-t "true") >> '(defvar macro-nil "false")))) >> (ewc-macro) *That's* a macro. eval-when-compile still outputs a value, but the macro call outputs code. Here, the .elc file will be the equivalent of: 'ewc-macro (defvar macro-nil "false") Line 1 is a no-op, but line 2 is just what you want. > Here, you're defining a macro at compilation time. When compiling this > file, the macro is known and (ewc-macro) expands to (defvar macro-nil > "false") so that's compiled into the elc file, and that's the only thing > that's loaded. > > If you try to load the .el file directly, then the macro is not defined, > and you're trying to call a function named (ewc-macro) which will fail. That's incorrect. Things inside the eval-when-compile get evaluated when the .el file is loaded, but not when the .elc file is loaded. It's *not* the equivalent of Common Lisp's (eval-when (compile) body...) -PJ Gehm's Corollary to Clark's Law: Any technology distinguishable from magic is insufficiently advanced.