[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Are nested defun's byte-compiled?

From: Drew Adams
Subject: Are nested defun's byte-compiled?
Date: Sun, 15 May 2005 15:47:51 -0700

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

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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]