lupton@uhccux.uhcc.hawaii.edu (Robert Lupton) (01/06/89)
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. Mail/News replies gratefully accepted. Robert (lupton@uhccux.uhcc.hawaii.edu)
Ram-Ashwin@cs.yale.edu (Ashwin Ram) (01/06/89)
In article <2941@uhccux.uhcc.hawaii.edu>, lupton@uhccux.uhcc.hawaii.edu (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. I think the "right" way to do this is to have your package of utilities "provide" a "feature" that you can then "require" wherever you need it. For example, you might put the following line in your c-utils.el file: (provide 'c-utils) Then you can ensure that the c-utils feature is present by saying: (require 'c-utils) or (require 'c-utils "file-to-load-from") This line will automatically load "c-utils" (or "file-to-load-from" in the second case) if the feature c-utils has not yet been provided. -- Ashwin.
matt@oddjob.uchicago.edu (Matt Crawford) (01/07/89)
Ashwin's reply about using provide and require is the correct solution, but in case you sometimes really do need to decide whether a function is defined, use (fboundp 'SYMBOL): T if SYMBOL's function definition is not void. Matt Crawford