From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.devel Subject: Q on byte-compile problem Date: Tue, 6 Jun 2006 12:19:42 -0700 Message-ID: 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 1149621611 24153 80.91.229.2 (6 Jun 2006 19:20:11 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 6 Jun 2006 19:20:11 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Jun 06 21:20:10 2006 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1Fnh5x-0005Jt-L4 for ged-emacs-devel@m.gmane.org; Tue, 06 Jun 2006 21:20:05 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Fnh5x-00055q-03 for ged-emacs-devel@m.gmane.org; Tue, 06 Jun 2006 15:20:05 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Fnh5k-00053y-7t for emacs-devel@gnu.org; Tue, 06 Jun 2006 15:19:52 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Fnh5i-00052D-Jg for emacs-devel@gnu.org; Tue, 06 Jun 2006 15:19:51 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Fnh5i-00052A-Em for emacs-devel@gnu.org; Tue, 06 Jun 2006 15:19:50 -0400 Original-Received: from [141.146.126.228] (helo=agminet01.oracle.com) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_3DES_EDE_CBC_SHA:24) (Exim 4.52) id 1FnhD9-0002sg-6r for emacs-devel@gnu.org; Tue, 06 Jun 2006 15:27:31 -0400 Original-Received: from rgmsgw300.us.oracle.com (rgmsgw300.us.oracle.com [138.1.186.49]) by agminet01.oracle.com (Switch-3.1.7/Switch-3.1.7) with ESMTP id k56JJm3Q021420 for ; Tue, 6 Jun 2006 14:19:49 -0500 Original-Received: from dradamslap (dhcp-amer-rmdc-csvpn-gw5-141-144-105-128.vpn.oracle.com [141.144.105.128]) by rgmsgw300.us.oracle.com (Switch-3.1.7/Switch-3.1.7) with SMTP id k56JJlkM000624 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO) for ; Tue, 6 Jun 2006 13:19:48 -0600 Original-To: "Emacs-Devel" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.6604 (9.0.2911.0) Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1807 X-Brightmail-Tracker: AAAAAQAAAAI= X-Brightmail-Tracker: AAAAAQAAAAI= X-Whitelist: TRUE X-Whitelist: TRUE X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:55758 Archived-At: 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'