Sender: usenet@jpl-devvax.jpl.nasa.gov (For NNTP so rrn will be able to post)
Nntp-Posting-Host: ai-cyclops
Reply-To: charest@aig.jpl.nasa.gov
Organization: NASA/Jet Propulsion Laboratory
References: <10026@uqcspe.cs.uq.oz.au>
Date: Fri, 28 Aug 1992 19:22:33 GMT
Lines: 34
In article <10026@uqcspe.cs.uq.oz.au>, gong@cs.uq.oz.au (Ming Gong) writes:
|> I want to know *at run time* whether or not a expression is a function.
|> Can some knowledgeable people tell me how?
If the expression is bound to a variable X then
(functionp x)
should do the job.
|> For example, I have a lisp function PLUS implementing
|> lambda x. lambda y. x + y
|> then (funcall (PLUS) 3) is a function and will printout something like
|> #<Function PLUS ....>.
Some observations: if PLUS is a Lisp function then the form (PLUS) is a call to that function with no arguments; furthermore (funcall (PLUS) 3) is a call to the *result* of (PLUS) with the argument 3. I'll assume that you mean (PLUS) returns the function object and that object is what prints as #<Function PLUS ....>. This suggests that PLUS is not an ordinary Lisp function object, but rather some custom data structure that you implemented yourself.
|> The questions are: can I access such information within a lisp program
|> and how?
If the functions in question are true Lisp function objects, then FUNCTIONP should work as described above. Otherwise, the answer depends on your implementation of these 'functions'. For example, if you used DEFSTRUCT to define the data structure then a type-discriminating predicate would be automatically created. E.g.,
(defstruct function
name
lambda-list
code)
> (setq test (make-function :name 'plus :lambda-list '(x y)