2

I've tried using functionp and fboundp, and am wondering what the difference is and how they can be used to maybe-call a function.

(functionp OBJECT) - Non-nil if OBJECT is a function.

(fboundp SYMBOL) - Return t if SYMBOL's function definition is not void.

For example, I'm trying to do:

(if (python-shell-get-buffer)
    .... 
    ....

But python-shell-get-buffer doesn't get defined until run-python has been run.
If I just try to call it, before its defined, I get:

Symbol's function definition is void: python-shell-get-buffer

I've tried using

(if (and (fboundp python-shell-get-buffer) (python-shell-get-buffer))

and

(if (and (functionp python-shell-get-buffer) (python-shell-get-buffer))

but they also result in

Symbol's value as variable is void: python-shell-get-buffer

How do I call a function which may or may not be defined ?

user2864740
  • 60,010
  • 15
  • 145
  • 220
AAAfarmclub
  • 2,202
  • 1
  • 19
  • 13
  • `(fboundp SYMBOL)` - supply a SYMBOL, such as `(fboundp 'python-shell-get-buffer)`. Use `functionp` when wishing to test the resulting *type* of object, once the expression is evaluated. – user2864740 Aug 28 '15 at 20:59
  • That's it. I didn't quote the symbol. – AAAfarmclub Aug 28 '15 at 21:04
  • `(if (and (fboundp 'python-shell-get-buffer) (python-shell-get-buffer))` seems to do what I want without choking – AAAfarmclub Aug 28 '15 at 21:07

0 Answers0