all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Are nested defun's byte-compiled?
@ 2005-05-15 22:47 Drew Adams
  2005-05-24 17:46 ` Drew Adams
  0 siblings, 1 reply; 7+ messages in thread
From: Drew Adams @ 2005-05-15 22:47 UTC (permalink / raw)


Is the code defining a nested defun byte-compiled when its enclosing defun
is compiled? Example source file foo.el:

(defcustom define-bar-flag t "Define `bar' if non-nil.")
(defun foo ()
  "Do foo stuff. Define `bar' if `define-bar-flag' is non-nil."
  (when define-bar-flag (defun bar () (bar-stuff)))
  (rest-of-foo-stuff))

Suppose foo.el is byte-compiled, and then foo.elc is loaded.

Is `define-bar-flag' eval'd when compiling foo? I assume not. I assume that
`bar' is not defined if `define-bar-flag' was set to nil before foo.elc is
loaded. I assume that `bar' is not defined until `(foo)' is executed, and
then only if `define-bar-flag' is non-nil.

When foo.el was byte-compiled, is bar's potential definition (the defun
itself) also byte-compiled or not? That is, if `(foo)' is executed after
loading foo.elc, which version of `bar' is defined, byte-compiled or not?

If the answer is that the non-compiled version of `bar' is defined, how can
the code be changed to make the compiled version be defined instead? Is this
a good way to do that?

(defun foo ()
  (when define-bar-flag (byte-compile (defun bar () (bar-stuff))))
  (rest-of-foo-stuff))

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

* Re: Are nested defun's byte-compiled?
       [not found] <mailman.52.1116355611.25862.help-gnu-emacs@gnu.org>
@ 2005-05-20 14:59 ` Stefan Monnier
  0 siblings, 0 replies; 7+ messages in thread
From: Stefan Monnier @ 2005-05-20 14:59 UTC (permalink / raw)


> (defun foo ()
>   "Do foo stuff. Define `bar' if `define-bar-flag' is non-nil."
>   (when define-bar-flag (defun bar () (bar-stuff)))

Using `defun' inside the body of a function is very poor style.
I.e. don't do it.

As for your question: the byte-compiler compiles all the code.


        Stefan

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

* RE: Are nested defun's byte-compiled?
  2005-05-15 22:47 Drew Adams
@ 2005-05-24 17:46 ` Drew Adams
  0 siblings, 0 replies; 7+ messages in thread
From: Drew Adams @ 2005-05-24 17:46 UTC (permalink / raw)


Trying this again, as I received no response. Thanks, Drew.

    Sent: Sunday, May 15, 2005 3:48 PM

    Is the code defining a nested defun byte-compiled when its
    enclosing defun
    is compiled? Example source file foo.el:

    (defcustom define-bar-flag t "Define `bar' if non-nil.")
    (defun foo ()
      "Do foo stuff. Define `bar' if `define-bar-flag' is non-nil."
      (when define-bar-flag (defun bar () (bar-stuff)))
      (rest-of-foo-stuff))

    Suppose foo.el is byte-compiled, and then foo.elc is loaded.

    Is `define-bar-flag' eval'd when compiling foo? I assume not. I
    assume that
    `bar' is not defined if `define-bar-flag' was set to nil before
    foo.elc is
    loaded. I assume that `bar' is not defined until `(foo)' is
    executed, and
    then only if `define-bar-flag' is non-nil.

    When foo.el was byte-compiled, is bar's potential definition (the defun
    itself) also byte-compiled or not? That is, if `(foo)' is executed after
    loading foo.elc, which version of `bar' is defined,
    byte-compiled or not?

    If the answer is that the non-compiled version of `bar' is
    defined, how can
    the code be changed to make the compiled version be defined
    instead? Is this
    a good way to do that?

    (defun foo ()
      (when define-bar-flag (byte-compile (defun bar () (bar-stuff))))
      (rest-of-foo-stuff))

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

* Re: Are nested defun's byte-compiled?
       [not found] <mailman.1588.1116958704.25862.help-gnu-emacs@gnu.org>
@ 2005-05-24 22:15 ` Thierry Emery
  2005-05-24 22:25   ` Drew Adams
  2005-05-25 15:53 ` Stefan Monnier
  1 sibling, 1 reply; 7+ messages in thread
From: Thierry Emery @ 2005-05-24 22:15 UTC (permalink / raw)


"Drew Adams" <drew.adams@oracle.com> writes:

> Trying this again, as I received no response. Thanks, Drew.
>
>     Sent: Sunday, May 15, 2005 3:48 PM
>
>     Is the code defining a nested defun byte-compiled when its enclosing
>     defun is compiled? Example source file foo.el:
>
>     (defcustom define-bar-flag t "Define `bar' if non-nil.")
>     (defun foo ()
>       "Do foo stuff. Define `bar' if `define-bar-flag' is non-nil."
>       (when define-bar-flag (defun bar () (bar-stuff)))
>       (rest-of-foo-stuff))
>
>     Suppose foo.el is byte-compiled, and then foo.elc

[random speculations snipped]

If you open foo.elc with Emacs, you can see that the compiled definition
for `foo' contains a compiled definition for `bar'.

If you still have a doubt, you can:
M-x load-file
foo.elc
ESC ESC :
(foo)
;; this defines `bar' and signals an error because `rest-of-foo-stuff'
;; is not defined...
M-x debug-on-entry
bar
ESC ESC :
(bar)
d
;; and you see:
Debugger entered--beginning evaluation of function call form:
* (byte-code "À �" [bar-stuff] 1)
* bar()
  eval((bar))
  eval-expression((bar) nil)
  call-interactively(eval-expression)


HTH,

Thierry
-- 
thierry |point| emery |chez| free |point| fr

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

* RE: Are nested defun's byte-compiled?
  2005-05-24 22:15 ` Thierry Emery
@ 2005-05-24 22:25   ` Drew Adams
  0 siblings, 0 replies; 7+ messages in thread
From: Drew Adams @ 2005-05-24 22:25 UTC (permalink / raw)


    >     Is the code defining a nested defun byte-compiled when 
    >     its enclosing defun is compiled?

  [Answer: yes. Plus clear explanation of how to determine this.]

Thanks.

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

* Re: Are nested defun's byte-compiled?
       [not found] <mailman.1588.1116958704.25862.help-gnu-emacs@gnu.org>
  2005-05-24 22:15 ` Thierry Emery
@ 2005-05-25 15:53 ` Stefan Monnier
  2005-05-25 16:23   ` Drew Adams
  1 sibling, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2005-05-25 15:53 UTC (permalink / raw)


> Trying this again, as I received no response. Thanks, Drew.

Don't I count?

   http://groups.google.com/groups?hl=fr&lr=&frame=right&th=b1e56f162e4b2044&seekm=mailman.52.1116355611.25862.help-gnu-emacs%40gnu.org#link2


-- Stefan

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

* RE: Are nested defun's byte-compiled?
  2005-05-25 15:53 ` Stefan Monnier
@ 2005-05-25 16:23   ` Drew Adams
  0 siblings, 0 replies; 7+ messages in thread
From: Drew Adams @ 2005-05-25 16:23 UTC (permalink / raw)


    > Trying this again, as I received no response. Thanks, Drew.

    Don't I count?


http://groups.google.com/groups?hl=fr&lr=&frame=right&th=b1e56f162e4b2044&se
ekm=mailman.52.1116355611.25862.help-gnu-emacs%40gnu.org#link2

Yes, of course you count. Sorry, I've had email problems recently; I didn't
get your reply, for some reason. Thanks.

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

end of thread, other threads:[~2005-05-25 16:23 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.52.1116355611.25862.help-gnu-emacs@gnu.org>
2005-05-20 14:59 ` Are nested defun's byte-compiled? Stefan Monnier
     [not found] <mailman.1588.1116958704.25862.help-gnu-emacs@gnu.org>
2005-05-24 22:15 ` Thierry Emery
2005-05-24 22:25   ` Drew Adams
2005-05-25 15:53 ` Stefan Monnier
2005-05-25 16:23   ` Drew Adams
2005-05-15 22:47 Drew Adams
2005-05-24 17:46 ` 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.