all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Q on byte-compile problem
@ 2006-06-06 19:19 Drew Adams
  2006-06-06 20:18 ` Stuart D. Herring
  0 siblings, 1 reply; 3+ messages in thread
From: Drew Adams @ 2006-06-06 19:19 UTC (permalink / raw)


I'm not suggesting there is a bug here (I don't know). I'm asking for help
understanding what to do (recommendations).

I define a macro `foo' in library `foo.el'. This macro constructs and evals
a `defun' using its argument (`bar') as the function to be defined.

I have a library `bar.el' that has two alternative, top-level definitions of
function `bar', depending on whether macro `foo' has been defined:

 (when (fboundp 'foo) (foo bar)) ; use foo to define bar
 (unless (fboundp 'foo) (defun bar ...)) ; std defun of bar

In Emacs 20, I have no problem byte-compiling and using library bar.

In Emacs 22:

1. If I byte-compile `bar.el' in a session that does not have library `foo'
loaded, then  I get a warning about a reference to free variable `bar' when
it tries to compile (foo bar). Seems normal: the compiler can't figure out
that (foo bar) is a macro expression.

2. If I byte-compile `bar.el' in a session that has library `foo' loaded,
then I get a warning that `bar' is not known to be defined (`bar' is used
elsewhere in file `bar.el'). Is this normal? Shouldn't the compiler eval the
(foo bar) and define `bar', so then (bar...) wouldn't be unrecognized? The
(foo bar) occurs before the use of `bar' in `bar.el'.

I'm not too worried about the warnings, in any case, but it would be nice to
eliminate them somehow - recommendations?

However, in Emacs 22:

A. If I load `bar.elc' that was compiled via #1 (with `foo'):

 a1) in a session in which library `foo' was not loaded - `bar's
     definition is, as I expected, the straight `defun' version
     (byte-compiled) [Good]

 a2) in a session in which library `foo' was loaded - I get this error at
     load time: "Symbol's value as variable is void: bar" [Bad].
     Nevertheless, `bar.elc' seems to load OK, and `bar' is defined OK
     (straight `defun' version).

I want a2 to pick up the `foo'-defined version of `bar'. Obviously I'm not
doing the right thing. However, I don't understand why loading `bar.elc'
chokes in a2. I would expect the (when (fboundp 'foo)...) envelope to
protect the call to macro `foo' during the load.

B. If I load `bar.elc' that was compiled via #2 (without `foo'):

 b1) in a session in which library `foo' was not loaded - `bar's
     definition is, as I expected, the straight `defun' version
     (byte-compiled) [Good]

 b2) in a session in which library `foo' was loaded - `bar's
     definition is, as I expected, the `foo'-defined version
     (byte-compiled) [Good]

In terms of executing `bar', both cases of both A and B work fine, but in a2
the straight `defun' version of `bar' is used, and I want the `foo'-defined
version to be used. IOW, I want the (when (fboundp 'foo)...) to be eval'd
when `bar.elc' is loaded, not just when it is compiled.

I see this in Elisp-manual node Eval During Compile:

     If functions are defined programmatically (with `fset' say), then
     `eval-and-compile' can be used to have that done at compile-time
     as well as run-time, so calls to those functions are checked (and
     warnings about "not known to be defined" suppressed).

So, I also tried putting `eval-and-compile' around both definitions, at the
top level, but that didn't help. Suggestions? Thx.

Just in case there is a bug, here is the Emacs version I'm using:

In GNU Emacs 22.0.50.1 (i386-mingw-nt5.1.2600)
 of 2006-03-20 on W2ONE
X server distributor `Microsoft Corp.', version 5.1.2600
configured using `configure --with-gcc (3.4) --cflags -Id:/g/include'

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

end of thread, other threads:[~2006-06-07  1:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-06-06 19:19 Q on byte-compile problem Drew Adams
2006-06-06 20:18 ` Stuart D. Herring
2006-06-07  1:57   ` Drew Adams

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.