This question is regarding the newer specification for functionp in
Cltl2 (pg 102-103.)
(defun foo ()
(print "hello")
)
I want to check later if "foo" is indeed a function.
(functionp 'foo)
returns (as per X3J13)
nil.
Could some one tell me some other way to check if foo is
a function?
i.e.,
(some-predicate-p 'foo)
>true
Thanks
Sanjay
In article <··········@agate.berkeley.edu>, ·····@robocop.Berkeley.EDU (Sanjay Sarma) writes:
> I want to check later if "foo" is indeed a function.
>
> (defun foo () ...)
> (functionp 'foo)
> nil
Well, the symbol FOO is not a function so this is not a surprise.
What you want to do is check to see that the symbol's "function slot"
is set to a function. You can do this with
(fboundp 'foo)
It would seem that some malicious hacker might try to set this slot to
something other than a function, just to trip up your call to FBOUNDP.
He might do this with
(setf (symbol-function 'foo) 3)
It turns out that the lisp i am using (Lucid) will not allow this.
> (setf (symbol-function 'foo) 3)
>>Error: The value of DEF, 3, should be a SYSTEM:PROCEDURE
EVAL:
Required arg 0 (EXPRESSION): (SETF (SYMBOL-FUNCTION (QUOTE FOO)) 3)
But i don't know if it is guaranteed that
(if (fboundp 'foo) (functionp (symbol-function 'foo)))
is always T.
rodrigo vanegas
··@cs.brown.edu
In article <················@fiji.cs.brown.edu> ··@cs.brown.edu (rodrigo vanegas) writes:
From: ··@cs.brown.edu (rodrigo vanegas)
What you want to do is check to see that the symbol's "function slot"
is set to a function. You can do this with
(fboundp 'foo)
This is somewhat incorrect, as fboundp is true for symbols naming a
macro or special form, but such symbols are not valid arguments as the
name of a function, e.g. as the first argument to FUNCALL. FBOUNDP
tests whether a name is globally bound to an "operator", that is, the
union of function, macro, and special form names.
But i don't know if it is guaranteed that
(if (fboundp 'foo) (functionp (symbol-function 'foo)))
is always T.
If FOO name a macro or special form, it is _completely_ _unspecified_
what (SYMBOL-FUNCTION 'FOO) will return (CLtL2 p.119). For example,
(SYMBOL-FUNCTION 'LET) might return 3.14159 or #'CADR, or (more
likely) some implementation-dependent object.
The correct test whether a symbol names a function is:
(defun fbound-to-function-p (symbol)
(and (fboundp symbol)
(not (macro-function symbol))
(not (special-operator-p symbol))))
Note that SPECIAL-OPERATOR-P is the new ANSI CL name for the old
SPECIAL-OPERATOR-P predicate.
In article <·················@vapor.Franz.COM>, ···@Franz.COM (Steve Haflich) writes:
> The correct test whether a symbol names a function is:
> (defun fbound-to-function-p (symbol)
> (and (fboundp symbol)
> (not (macro-function symbol))
> (not (special-operator-p symbol))))
> Note that SPECIAL-OPERATOR-P is the new ANSI CL name for the old
> SPECIAL-OPERATOR-P predicate.
You mean the old SPECIAL-FORM-P, right?
rodrigo vanegas
··@cs.brown.edu