From: "Drew Adams" <drew.adams@oracle.com>
Subject: Q on byte-compile problem
Date: Tue, 6 Jun 2006 12:19:42 -0700 [thread overview]
Message-ID: <MEEKKIABFKKDFJMPIOEBOEAGDCAA.drew.adams@oracle.com> (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'
next reply other threads:[~2006-06-06 19:19 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-06-06 19:19 Drew Adams [this message]
2006-06-06 20:18 ` Q on byte-compile problem Stuart D. Herring
2006-06-07 1:57 ` Drew Adams
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=MEEKKIABFKKDFJMPIOEBOEAGDCAA.drew.adams@oracle.com \
--to=drew.adams@oracle.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.