NightStruck · 2022-08-04 05:43
i'm kinda confused on what makes `fboundp` and `functionp` functionally different from each other. it seems to me that i can just swap between the two whenever.
ieure · 2022-08-04 06:57
`FUNCTIONP` tells you if *its argument is* a function value; `FBOUNDP` tells you if *a symbol has* a function value bound to it.
ELISP> (functionp 'car)
t
ELISP> (fboundp 'car)
t
ELISP> (functionp (lambda ()))
t
ELISP> (fboundp (lambda ()))
*** Eval error *** Wrong type argument: symbolp, (closure (t) nil)
organic-bookworm · 2022-08-04 08:07
I'll add a bit.
And `(fboundp 'sym)` is ~~functionally equivalent~~ to `(functionp (symbol-function 'sym))`, so you could say `functionp` is a ~~more generic function~~.
EDIT: See [u/xtifr](https://www.reddit.com/r/emacs/comments/wft3je/comment/iiwci66) comment.
xtifr · 2022-08-04 10:21
Also, fboundp tells you whether the symbol's function cell contains *something*, not whether that something is a valid function.
ELISP> (fset 'foo "abc")
"abc"
ELISP> (fboundp 'foo)
t
ELISP> (functionp 'foo)
nil
(The docs assure me that there are reasons for putting a keymap or keyboard macro in a symbol's function cell, but I'm fuzzy on the details.)
NightStruck · 2022-08-04 10:53
thanks everyone, appreciate the examples!
organic-bookworm · 2022-08-04 11:09
Good point.
mickeyp · 2022-08-04 12:01
> (The docs assure me that there are reasons for putting a keymap or keyboard macro in a symbol's function cell, but I'm fuzzy on the details.)
You can`fset` keyboard macros with `kmacro-lambda-form` and a vector of the actions-to-be. That's what `insert-kbd-macro` code generates for you.