From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Denis Bueno Newsgroups: gmane.emacs.help Subject: Re: Error: Symbol's value as variable is void Date: Fri, 25 Mar 2005 14:26:59 -0500 Message-ID: <6dbd4d0005032511264f58d3a5@mail.gmail.com> References: Reply-To: Denis Bueno NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1111779991 19722 80.91.229.2 (25 Mar 2005 19:46:31 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 25 Mar 2005 19:46:31 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Mar 25 20:46:31 2005 Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1DEulH-00072q-Hi for geh-help-gnu-emacs@m.gmane.org; Fri, 25 Mar 2005 20:46:27 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DEv0p-0008A8-9e for geh-help-gnu-emacs@m.gmane.org; Fri, 25 Mar 2005 15:02:31 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1DEuyP-0007Pe-UC for help-gnu-emacs@gnu.org; Fri, 25 Mar 2005 15:00:02 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1DEuyG-0007I7-N4 for help-gnu-emacs@gnu.org; Fri, 25 Mar 2005 14:59:54 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DEuyD-00074h-6Q for help-gnu-emacs@gnu.org; Fri, 25 Mar 2005 14:59:49 -0500 Original-Received: from [64.233.184.192] (helo=wproxy.gmail.com) by monty-python.gnu.org with esmtp (Exim 4.34) id 1DEuSR-00067x-A4 for help-gnu-emacs@gnu.org; Fri, 25 Mar 2005 14:26:59 -0500 Original-Received: by wproxy.gmail.com with SMTP id 36so1013801wra for ; Fri, 25 Mar 2005 11:26:59 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:references; b=H43xpvqy8TzVqsu5fX3MaTEy0V8BkJAP3uBfG3x8EQZ9M2ZUQEOEYG/R7eDNeeNeN7wJ2/7LQt7BfW09ZMswDYntQXA8RRl48AP9l+rDonG7P5LU6hTOQ4rS6K4BWty8lBF+iSOCEC2mDO3ZHU79iJyIspKI/b/GxzOs+qbNfHk= Original-Received: by 10.54.46.49 with SMTP id t49mr487200wrt; Fri, 25 Mar 2005 11:26:59 -0800 (PST) Original-Received: by 10.54.43.7 with HTTP; Fri, 25 Mar 2005 11:26:59 -0800 (PST) Original-To: Joe Corneli , help-gnu-emacs@gnu.org In-Reply-To: X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org X-MailScanner-To: geh-help-gnu-emacs@m.gmane.org Xref: news.gmane.org gmane.emacs.help:25154 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:25154 On Fri, 25 Mar 2005 12:28:38 -0600, Joe Corneli wrote: > > I wrote some code that contains the following forms: > > (defvar nero-link-regexp "\\[\\([0-9]+\\)\\]" > "Regular expression that tells nero what links look like. > The first parenthesized subexpression is the unique string > denoting the webpage to load, which will sought among the > references.") I'm guessing that if you wrap the above defvar in an (eval-when-compile ...) and leave the other eval-when-compile present, all will be fine. > > (defvar nero-font-lock-keywords > (eval-when-compile > (list `(,nero-link-regexp . font-lock-keyword-face))) > "Font lock for `nero-mode'. > Currently, only numbered links are fontified.") > > These work fine for me, but another person using the code reports the > following error upon byte-compiling: > > Compiling file /stor/garray/src/nero.el at Fri Mar 25 08:21:48 2005 > nero.el:295:33:Error: Symbol's value as variable is void: nero-link-regexp > > I don't see any such error when I byte compile. I'm just curious to > know if using `eval-when-compile' here is bad form, or what. I think > I've seen it being used in other packages in a similar context, but I > don't understand it well enough to know whether I should be using it > here. > > Removing it did make the other user's error go away. I told him to > create a bug report, but if its just the fault of my bad code, I'd > like to know. More generally, as a point of style, when is it good to > use `eval-when-compile' Seems silly, but I think the answer is "whenever you need to evaluate something at compile time". I once needed to use a similar form (albeit I was programming in Common Lisp at the time, but nevertheless), because I needed to evaluate a constant at compile-time. In emacs lisp, the code would have looked something like this: (defvar c1 1) (defvar c2 2) (defvar c3 3) (defun foo (x ...) (case x ((eval-when-compile c1) (do-something)) ((eval-when-compile c2) (do-something-else)))) The reason I need the eval-when-compile was that `case' by default doesn't evaluate its cases; so if eval-when-compile weren't there, `case' would compare the value of x to the symbol c1, then c2, etc. Usu. the case described above doesn't come up because you do things like: (case x (3 (do-something)) (4 (do-something-else))) i.e., you have literal values as your cases. I didn't in my case. (Note: The `case' form might work differently in emacs lisp; but that's the way it works in common lisp. I'm just trying to give an example of what I think is a proper usage of `eval-when-compile'.) (Just to avoid befuddlement, the common lisp code looked like: (defconstant c1 1) (defconstant c2 2) (defun foo (x ...) (case x (#.c1 (do-something)) (#.c2 (do-something-else)))) In CL #. is a read-macro which evaluates its argument at read-time.) Hope I haven't confused you. =] -- Denis Bueno PGP: http://pgp.mit.edu:11371/pks/lookup?search=0xA1B51B4B&op=index