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: Sat, 28 Jul 2012 11:04:55 -0700 Message-ID: References: <871ujx94qo.fsf@Rainer.invalid> <871ujxd8in.fsf@kuiper.lan.informatimago.com> <87y5m5rt31.fsf@Rainer.invalid> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1343498701 14801 80.91.229.3 (28 Jul 2012 18:05:01 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 28 Jul 2012 18:05:01 +0000 (UTC) Cc: emacs-devel@gnu.org To: Achim Gratz Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Jul 28 20:05:01 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 1SvBNt-0005ok-Nt for ged-emacs-devel@m.gmane.org; Sat, 28 Jul 2012 20:05:01 +0200 Original-Received: from localhost ([::1]:59925 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SvBNt-0000wD-0n for ged-emacs-devel@m.gmane.org; Sat, 28 Jul 2012 14:05:01 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:56126) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SvBNr-0000w6-3b for emacs-devel@gnu.org; Sat, 28 Jul 2012 14:04:59 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SvBNq-0004Se-05 for emacs-devel@gnu.org; Sat, 28 Jul 2012 14:04:59 -0400 Original-Received: from mail-lpp01m010-f41.google.com ([209.85.215.41]:63155) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SvBNp-0004SY-OU for emacs-devel@gnu.org; Sat, 28 Jul 2012 14:04:57 -0400 Original-Received: by lahi5 with SMTP id i5so2993635lah.0 for ; Sat, 28 Jul 2012 11:04:56 -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 :content-transfer-encoding; bh=4EANdU/p17Xx4MOXBKAB+k5EB/2OW+Jd6yD4IM+N1zk=; b=qYSbmQz1lq1JE/pIvPGH8O9pcX2eCZLELh1DLDa4gOIL+gEx+qBBmOV+cYswhCNJAO lkidoo0ru1NkGkO8Ac6TNIYrXZq3MOGRRehRHURDcUiQvm9wceABwzpLZ4kJ222QPktp Er0w5ZQB8MOMhte7M41wPa/8vvZqpVw6qLIVaI+5r4KycCCUgvUMaT5geS/PI1k4Zj/u GQ5pOWr3rn/10qV765AIXn8RHSXnkfVCIcoM61f0DIVe9ATE3q0gRPIbNMjQqK4qCeHT klRjdpc6/UKIAAcfueYGn7Immb1NVHJztV0htdOMCyZejvdKs23ecVWSRAxCEOb5S88Z 0erw== Original-Received: by 10.152.146.163 with SMTP id td3mr6551751lab.26.1343498695928; Sat, 28 Jul 2012 11:04:55 -0700 (PDT) Original-Received: by 10.112.5.102 with HTTP; Sat, 28 Jul 2012 11:04:55 -0700 (PDT) In-Reply-To: <87y5m5rt31.fsf@Rainer.invalid> X-Google-Sender-Auth: of4vTjn29vjkXgGgnArvj9DNwBo X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.215.41 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:151941 Archived-At: On Fri, Jul 27, 2012 at 10:50 AM, Achim Gratz wrote: > Pascal J. Bourguignon writes: >> C-h f eval-when-compile RET >> >> Like `progn', but evaluates the body at compile time if you're compi= ling. >> Thus, the result of the body appears to the compiler as a quoted con= stant. >> In interpreted code, this is entirely equivalent to `progn'. >> >> What more can I add? > > I read that. It doesn't seem to work that way or has some strings > attached that aren't obvious to me from the documentation. > >> The above source will evaluate, when you compile the file: >> >> (defvar unquoted-t "true") >> '(defvar quoted-nil "false") > > No. They will evaluate to > > unquoted-t > (defvar quoted-nil "false") > > The unquoted variant was only there to check if maybe there's another > `(quote =85)=B4 snuck in. I expected the defvar form to compile, but it > doesn't. You missed this part: Thus, the result of the body appears to the compiler as a quoted const= ant. So they really evaluate to: 'unquoted-t '(defvar quoted-nil "false") Which of course does nothing, so the compiler optimizes it away. You know what you could do? --- (eval (eval-when-compile (if nil '(defvar quoted-t "true") '(defvar quoted-nil "false"))) --- That'll compile to: --- (eval '(defvar quoted-nil "false")) --- -PJ Gehm's Corollary to Clark's Law: Any technology distinguishable from magic is insufficiently advanced.