[comp.emacs] fboundp/provide/require

merlyn@intelob.biin.com (Randal L. Schwartz @ Stonehenge) (01/07/89)

In article <2941@uhccux.uhcc.hawaii.edu>, lupton@uhccux (Robert Lupton) writes:
| If I want to find if a name is defined as a function how do I do it?
| Specifically, I have a package of utilities that define functions
| like malloc (to produce a template for mallocing stuff), fopen, ...
| and I want to put a line in my c-mode-hook that looks like
| 
| 	(if (= malloc nil)
| 	    (load-file "c-utils.elc"))
| 
| but it doesn't work (and 'malloc doesn't work either). I don't want to
| use auto-load as I want to load on any of the functions in the file,
| and I don't want to wrap all the definitions in a defun and auto-load on that.

You can use `fboundp' like so:

   (if (not (fboundp 'malloc)) (load-file "c-utils.elc"))

although provide/require might be better.  To use that, stick:

   (provide 'c-utils)

in the beginning of the c-utils.el[c] file, and:

   (require 'c-utils)

in place of your 'if' test; it replaces the whole test, not just the
`if' predicate.  Note that "c-utils.elc" must now be in your load-path
(set with EMACSLOADPATH environment variable or `set[q]').  If not, you
can cheat, and say:

  (require 'c-utils "/usr/you/very/long/path/c-utils.elc")

See doc-strings on these functions for details.  Your mileage may
vary.  :-)
-- 
Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095
on contract to BiiN Technical Information Services (for now :-),
in a former Intel building in Hillsboro, Oregon, USA.
<merlyn@intelob.biin.com> or ...!tektronix!inteloa[!intelob]!merlyn
SOME MAILERS REQUIRE <merlyn@intelob.intel.com> GRRRRR!
Standard disclaimer: I *am* my employer!