unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Error: Symbol's value as variable is void
@ 2005-03-25 18:28 Joe Corneli
  2005-03-25 19:26 ` Denis Bueno
  0 siblings, 1 reply; 7+ messages in thread
From: Joe Corneli @ 2005-03-25 18:28 UTC (permalink / raw)



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.")

(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'?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Error: Symbol's value as variable is void
  2005-03-25 18:28 Joe Corneli
@ 2005-03-25 19:26 ` Denis Bueno
  0 siblings, 0 replies; 7+ messages in thread
From: Denis Bueno @ 2005-03-25 19:26 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Error: Symbol's value as variable is void
       [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-28 20:18 ` Kevin Rodgers
  1 sibling, 2 replies; 7+ messages in thread
From: Thien-Thi Nguyen @ 2005-03-26  0:00 UTC (permalink / raw)


Joe Corneli <jcorneli@math.utexas.edu> writes:

> when is it good to use `eval-when-compile'?

when you want to evaluate something at compilation time.

if this is not completely clear to you, probably it is
best to drop its use and come back to it later (if ever).

this kind of solution hints that the problem is of the
family of problems relating to premature optimization.
those kinds of problems are interesting in their own
right, of course.  no easier way to make a mess than
to insist on phase separation...

thi

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Error: Symbol's value as variable is void
  2005-03-26  0:00 ` Error: Symbol's value as variable is void Thien-Thi Nguyen
@ 2005-03-26  2:48   ` Joe Corneli
       [not found]   ` <mailman.255.1111806378.28103.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 7+ messages in thread
From: Joe Corneli @ 2005-03-26  2:48 UTC (permalink / raw)




   > when is it good to use `eval-when-compile'?

   when you want to evaluate something at compilation time.

   if this is not completely clear to you, probably it is
   best to drop its use and come back to it later (if ever).

I'm OK with that, but still, I've seen it used, for example, in the
definition of `lisp-imenu-generic-expression'.  It might be helpful to
me to know why it is used there.  I guess otherwise the regexp-opt
forms would not be evaluated when the code was compiled, leading to
disaster.  And I also suppose that this situation is precipitated by
the use of `purecopy'.  So what are the benefits of `purecopy'?
One thing that is kind of quirky is that 
 
 (describe-variable 'lisp-font-lock-keywords-1)

produces a window headed off by "lisp-font-lock-keywords-1's value is
shown below."  No source file.  Wow, weird.

Anyway, I think I was mislead in thinking that it was the things
(potentially) inside of `eval-when-compile' that would precipitate
needing to use it.  Apparently that is not the case.

So, its all becoming much clearer.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Error: Symbol's value as variable is void
       [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
  0 siblings, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2005-03-27  0:12 UTC (permalink / raw)


> produces a window headed off by "lisp-font-lock-keywords-1's value is
> shown below."  No source file.  Wow, weird.

Hmm... checking here... can't reproduce it.  I guess you're using
Emacs-21.[1234] and it's been fixed in the Emacs-CVS version.


        Stefan

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Error: Symbol's value as variable is void
  2005-03-27  0:12     ` Stefan Monnier
@ 2005-03-27  0:45       ` Joe Corneli
  0 siblings, 0 replies; 7+ messages in thread
From: Joe Corneli @ 2005-03-27  0:45 UTC (permalink / raw)




   > produces a window headed off by "lisp-font-lock-keywords-1's value is
   > shown below."  No source file.  Wow, weird.

   Hmm... checking here... can't reproduce it.  I guess you're using
   Emacs-21.[1234] and it's been fixed in the Emacs-CVS version.

No, I think I just misread -- didn't follow past the first "link":


lisp-font-lock-keywords's value is shown below.
                                         ^^^^^
Default expressions to highlight in Lisp modes.

Defined in `font-lock'.
            ^^^^^^^^^



The format is just a bit different from what I was used to.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Error: Symbol's value as variable is void
       [not found] <mailman.227.1111777231.28103.help-gnu-emacs@gnu.org>
  2005-03-26  0:00 ` Error: Symbol's value as variable is void Thien-Thi Nguyen
@ 2005-03-28 20:18 ` Kevin Rodgers
  1 sibling, 0 replies; 7+ messages in thread
From: Kevin Rodgers @ 2005-03-28 20:18 UTC (permalink / raw)


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.")
 >
 > (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.

You don't get an error because you have nero.el[c] already loaded when
you byte compile it, but the other person doesn't.  It's more reliable
to byte compile .el files in an uncustomized emacs (i.e. invoked with -q
and perhaps --no-site-file).

 > 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'?

Only when you need it.  But since the simpler form is equivalent for
your purposes (I assume), why use the more complex eval-when-compile and
backquote form?

(defvar nero-font-lock-keywords
   (list (cons nero-link-regexp 'font-lock-keyword-face))
   "Font lock for `nero-mode'.
Currently, only numbered links are fontified.")

-- 
Kevin Rodgers

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2005-03-28 20:18 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.227.1111777231.28103.help-gnu-emacs@gnu.org>
2005-03-26  0:00 ` Error: Symbol's value as variable is void 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
2005-03-25 18:28 Joe Corneli
2005-03-25 19:26 ` Denis Bueno

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).