unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Question about byte-compiler warning
@ 2007-09-25 15:38 Vinicius Jose Latorre
  2007-09-25 17:13 ` Stefan Monnier
  2007-09-26 16:30 ` Richard Stallman
  0 siblings, 2 replies; 6+ messages in thread
From: Vinicius Jose Latorre @ 2007-09-25 15:38 UTC (permalink / raw)
  To: GNU Emacs (devel)

Hi,


Create a test file like:

test.el:
========
(cond
 ((featurep 'xemacs)
  (defun bar ()
    (message "bar XEmacs"))
  (defun foo ()
    (bar)))
 (t
  (defun bar ()
    (message "bar Emacs"))
  (defun foo ()
    (bar))))

(defun foobar ()
  (interactive)
  (foo))
========


Now byte-compile the file above.

The byte-compiler gives the following warning:

    In end of data:
    test.el:17:1:Warning: the following functions are not known to be 
defined:
        bar, foo


But aren't these functions (bar and foo) defined using cond construct?

Why does the byte-compiler give this warning?


Vinicius

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

* Re: Question about byte-compiler warning
  2007-09-25 15:38 Question about byte-compiler warning Vinicius Jose Latorre
@ 2007-09-25 17:13 ` Stefan Monnier
  2007-09-25 18:51   ` Vinicius Jose Latorre
  2007-09-26 16:30 ` Richard Stallman
  1 sibling, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2007-09-25 17:13 UTC (permalink / raw)
  To: Vinicius Jose Latorre; +Cc: GNU Emacs (devel)

> Create a test file like:

> test.el:
> ========
> (cond
> ((featurep 'xemacs)
>  (defun bar ()
>    (message "bar XEmacs"))
>  (defun foo ()
>    (bar)))
> (t
>  (defun bar ()
>    (message "bar Emacs"))
>  (defun foo ()
>    (bar))))

> (defun foobar ()
>  (interactive)
>  (foo))
> ========


> Now byte-compile the file above.

> The byte-compiler gives the following warning:

>    In end of data:
>    test.el:17:1:Warning: the following functions are not known to be
> defined:
>        bar, foo


> But aren't these functions (bar and foo) defined using cond construct?

> Why does the byte-compiler give this warning?

The byte-compiler only considers as defined a function which is trivially
obviously defined without having to do any kind of analysis.  I.e. it
doesn't look inside conditionals (or even inside `let's) to figure out what
might be defined in there.

A workaround I use sometimes is

   (defalias 'foo
     (if <toto>
         (lambda (bla) bli)
       (lambda (blo) blu)))

When the condition <toto> is used for several functions, this is a bit
inconvenient, tho.


        Stefan

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

* Re: Question about byte-compiler warning
  2007-09-25 17:13 ` Stefan Monnier
@ 2007-09-25 18:51   ` Vinicius Jose Latorre
  2007-09-26 14:06     ` Stefan Monnier
  0 siblings, 1 reply; 6+ messages in thread
From: Vinicius Jose Latorre @ 2007-09-25 18:51 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: GNU Emacs (devel)

Stefan Monnier wrote:
>> Create a test file like:
>>     
>
>   
>> test.el:
>> ========
>> (cond
>> ((featurep 'xemacs)
>>  (defun bar ()
>>    (message "bar XEmacs"))
>>  (defun foo ()
>>    (bar)))
>> (t
>>  (defun bar ()
>>    (message "bar Emacs"))
>>  (defun foo ()
>>    (bar))))
>>     
>
>   
>> (defun foobar ()
>>  (interactive)
>>  (foo))
>> ========
>>     
>
>
>   
>> Now byte-compile the file above.
>>     
>
>   
>> The byte-compiler gives the following warning:
>>     
>
>   
>>    In end of data:
>>    test.el:17:1:Warning: the following functions are not known to be
>> defined:
>>        bar, foo
>>     
>
>
>   
>> But aren't these functions (bar and foo) defined using cond construct?
>>     
>
>   
>> Why does the byte-compiler give this warning?
>>     
>
> The byte-compiler only considers as defined a function which is trivially
> obviously defined without having to do any kind of analysis.  I.e. it
> doesn't look inside conditionals (or even inside `let's) to figure out what
> might be defined in there.
>
> A workaround I use sometimes is
>
>    (defalias 'foo
>      (if <toto>
>          (lambda (bla) bli)
>        (lambda (blo) blu)))
>
> When the condition <toto> is used for several functions, this is a bit
> inconvenient, tho.
>   

Ok, but wasn't the construction:

(cond
   ((featurep 'xemacs)
     <xemacs-part> )
   (t
     <emacs-part> ))

recognized by the byte-compiler as a kind of conditional byte-compilation?


BTW, the byte-compiler gives no warning to the construction:

(eval-and-compile
   (cond
     ((featurep 'xemacs) <xemacs-part>)
     (t <emacs-part> ))))

It could also be used as an alternative construction.


Vinicius

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

* Re: Question about byte-compiler warning
  2007-09-25 18:51   ` Vinicius Jose Latorre
@ 2007-09-26 14:06     ` Stefan Monnier
  2007-09-26 16:35       ` Vinicius Jose Latorre
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2007-09-26 14:06 UTC (permalink / raw)
  To: Vinicius Jose Latorre; +Cc: GNU Emacs (devel)

> Ok, but wasn't the construction:

> (cond
>   ((featurep 'xemacs)
>     <xemacs-part> )
>   (t
>     <emacs-part> ))

> recognized by the byte-compiler as a kind of conditional byte-compilation?

It is, but that is not enough.  The same problem occurs with

  (let ((toto 1))
    (defun foo ()))

  (defun bar ()
    (foo))

In this case, the byte-compiler will also fail to see that `foo' is being
defined and will hence signal "Warning: the function `foo' is not known to
be defined".

> (eval-and-compile
>   (cond
>     ((featurep 'xemacs) <xemacs-part>)
>     (t <emacs-part> ))))

> It could also be used as an alternative construction.

eval-and-compile is ugly.


        Stefan

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

* Re: Question about byte-compiler warning
  2007-09-25 15:38 Question about byte-compiler warning Vinicius Jose Latorre
  2007-09-25 17:13 ` Stefan Monnier
@ 2007-09-26 16:30 ` Richard Stallman
  1 sibling, 0 replies; 6+ messages in thread
From: Richard Stallman @ 2007-09-26 16:30 UTC (permalink / raw)
  To: Vinicius Jose Latorre; +Cc: emacs-devel

The compiler is not smart enough to deduce that this code

    (cond
     ((featurep 'xemacs)
      (defun bar ()
	(message "bar XEmacs"))
      (defun foo ()
	(bar)))
     (t
      (defun bar ()
	(message "bar Emacs"))
      (defun foo ()
	(bar))))

always defines bar.  And it is not smart enough to recognize that each
use of bar is in the same conditionals as some definition of bar.

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

* Re: Question about byte-compiler warning
  2007-09-26 14:06     ` Stefan Monnier
@ 2007-09-26 16:35       ` Vinicius Jose Latorre
  0 siblings, 0 replies; 6+ messages in thread
From: Vinicius Jose Latorre @ 2007-09-26 16:35 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: GNU Emacs (devel)

Stefan Monnier wrote:
>> (eval-and-compile
>>   (cond
>>     ((featurep 'xemacs) <xemacs-part>)
>>     (t <emacs-part> ))))
>>     
>> It could also be used as an alternative construction.
>>     
>
> eval-and-compile is ugly.
>   

Yep, it's ugly, but it works, that is, no warning.

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

end of thread, other threads:[~2007-09-26 16:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-09-25 15:38 Question about byte-compiler warning Vinicius Jose Latorre
2007-09-25 17:13 ` Stefan Monnier
2007-09-25 18:51   ` Vinicius Jose Latorre
2007-09-26 14:06     ` Stefan Monnier
2007-09-26 16:35       ` Vinicius Jose Latorre
2007-09-26 16:30 ` Richard Stallman

Code repositories for project(s) associated with this public inbox

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

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