ekberg@home.csc.ti.com (Tom Ekberg) (01/05/88)
I have been unable to locate a function like the Common Lisp function named functionp. There are some functions which are similar, but none I found worked on all functions, so I wrote a function to handle this. How does the following definition appear to your critical eyes? (defun functionp (object) "Returns t if OBJECT is a function." (cond ((subrp object) t) ((commandp object) t) ((listp object) (eq (car object) 'lambda)) (t nil))) In case you are wondering, I am working on a function named describe which works like the Common Lisp describe function to give a description of any object given to it. The function names functionp is an essential part of the describe function. -- tom (aisle C-4L), EKBERG%TI-CSL@CSNET-RELAY, TI-CSL!EKBERG@IM4U.UUCP
Ram-Ashwin@cs.yale.edu (Ashwin Ram) (01/06/88)
In article <39315@ti-csl.CSNET>, ekberg@home (Tom Ekberg) writes: > ... How does the following > definition appear to your critical eyes? > > (defun functionp (object) > "Returns t if OBJECT is a function." > (cond ((subrp object) > t) > ((commandp object) > t) > ((listp object) > (eq (car object) 'lambda)) > (t > nil))) How about just: (or (subrp object) (commandp object) (and (listp object) (eq (car object) 'lambda))) -- Ashwin Ram -- ARPA: Ram-Ashwin@cs.yale.edu UUCP: {decvax,linus,seismo}!yale!Ram-Ashwin BITNET: Ram@yalecs
cef@H.GP.CS.CMU.EDU (Charles Fineman) (01/06/88)
There are two functions you may be interested in: fboundp & symbol-function The former tells you (given an sexpr), wether the evaluation of the argument has a functional value. If it does, the later will return it to you. Note: if the symbol has no functional value, symbol-function will signal an error (you could catch it with an unwind-protect (or some such beast) but that's another issue. <Slight course alteration> Some of these functions are rather obscure (e.g. fboundp, mkunbound). The way I found out about them was by writting a simple c program (I have since lost it :-( ) that went through a specified group of .c and .el files pulling out all the symbol and function definitions and building a SCRIBE file from the data. I grouped the functions into chapters according the file they were in. SCRIBE automagically built me a table of contents. It has been *INVALUABLE* to me as a reference manual. I may have a few spare hours this week, perhaps I will hack up another program to do this and post it. I'm learning TEX now so the output will undoubtedly (sp?) in TEXan. It certainly won't be the reference manual the GNU people are working on, but I think that many of you serious/novice ELISP hackers will find as useful as I do. Charles Fineman Carnegie-Mellon University cef@h.cs.cmu.edu (via seismo)
trost@reed.UUCP (Bill Trost) (01/22/88)
In article <39315@ti-csl.CSNET>, ekberg@home (Tom Ekberg) writes: > ... How does the following definition appear to your critical eyes? > > (defun functionp (object) > "Returns t if OBJECT is a function." > (cond ((subrp object) t) > ((commandp object) t) > ((listp object) (eq (car object) 'lambda))) ;modified to be cleaner lisp and to avoid line-counter problems Sorry I'm following up so late on this one, but that's what happens when people go home for Christmas break. Anyhow, what ya'll are most definitely looking is fboundp, which returns t if the argument has a function definition. If you want to get at that definition, use symbol-function. Be warned that macros are strings attatched to the function definition, so you may want to check for that as well. -- ...!(ogcvax|tektronix)!reed!trost @ All characters @ My opinions may or "Ooh ick!" -- Penfold, anonymous @ are ficticious @ may not represent assistant of *Dangermouse*, the @ unless they @ those of my employer, world's Greatest Secret Agent(TM) @ are real. @ etc, etc.
rlk@think.COM (Robert Krawitz) (01/23/88)
In article <8098@reed.UUCP> trost@reed.UUCP (Bill Trost) writes: ]In article <39315@ti-csl.CSNET>, ekberg@home (Tom Ekberg) writes: ]> ... How does the following definition appear to your critical eyes? ]> ]> (defun functionp (object) ]> "Returns t if OBJECT is a function." ]> (cond ((subrp object) t) ]> ((commandp object) t) ]> ((listp object) (eq (car object) 'lambda))) ] ;modified to be cleaner lisp and to avoid line-counter problems ] ]Anyhow, what ya'll are most definitely looking is fboundp, which ]returns t if the argument has a function definition. If you want to ]get at that definition, use symbol-function. Be warned that macros (keyboard macros, that is; not lisp macros, which are a list whose car is 'macro) ]are strings attatched to the function definition, so you may want to ]check for that as well. Fboundp checks that a SYMBOL has a function definition. Bill has something else in mind, namely checking that an OBJECT is a function. Actually, a better way to write this is (defun functionp (object) (or (subrp object) (commandp object) (and (listp object) (or (eq (car object) 'lambda) (eq (car object) 'macro))))) harvard >>>>>> | Robert Krawitz <rlk@think.com> bloom-beacon > |think!rlk ihnp4 >>>>>>>> . rlk@a.HASA.disorg