all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Denis Bueno <dbueno@gmail.com>
Subject: Re: Error: Symbol's value as variable is void
Date: Fri, 25 Mar 2005 14:26:59 -0500	[thread overview]
Message-ID: <6dbd4d0005032511264f58d3a5@mail.gmail.com> (raw)
In-Reply-To: <E1DEtXy-0005uB-00@lab45.ma.utexas.edu>

On Fri, 25 Mar 2005 12:28:38 -0600, Joe Corneli
<jcorneli@math.utexas.edu> 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

  reply	other threads:[~2005-03-25 19:26 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-25 18:28 Error: Symbol's value as variable is void Joe Corneli
2005-03-25 19:26 ` Denis Bueno [this message]
     [not found] <mailman.227.1111777231.28103.help-gnu-emacs@gnu.org>
2005-03-26  0:00 ` Thien-Thi Nguyen
2005-03-26  2:48   ` Joe Corneli
     [not found]   ` <mailman.255.1111806378.28103.help-gnu-emacs@gnu.org>
2005-03-27  0:12     ` Stefan Monnier
2005-03-27  0:45       ` Joe Corneli
2005-03-28 20:18 ` Kevin Rodgers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6dbd4d0005032511264f58d3a5@mail.gmail.com \
    --to=dbueno@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.