Is there a CL-standard way to distinguish between a generic function and
non-GF? Nothing in CLHS jumps out at me as a direct or indirect
solution, but I think my imagination must be failing me.
kt
--
Home? http://tilton-technology.com
Cells? http://www.common-lisp.net/project/cells/
Cello? http://www.common-lisp.net/project/cello/
Why Lisp? http://alu.cliki.net/RtL%20Highlight%20Film
Your Project Here! http://alu.cliki.net/Industry%20Application
On Fri, 2 Jul 2004, Kenny Tilton wrote:
> Is there a CL-standard way to distinguish between a generic function and
> non-GF? Nothing in CLHS jumps out at me as a direct or indirect
> solution, but I think my imagination must be failing me.
TYPEP?
(defgeneric foo ())
(defun bar ())
(typep #'foo 'generic-function) => T
(typep #'bar 'generic-function) => NIL
Matthew Danish wrote:
> On Fri, 2 Jul 2004, Kenny Tilton wrote:
>
>>Is there a CL-standard way to distinguish between a generic function and
>>non-GF? Nothing in CLHS jumps out at me as a direct or indirect
>>solution, but I think my imagination must be failing me.
>
>
> TYPEP?
>
> (defgeneric foo ())
> (defun bar ())
> (typep #'foo 'generic-function) => T
> (typep #'bar 'generic-function) => NIL
>
Nope, too easy. :)
I had checked the CPL of the class of a GF:
CTK(57): (class-of (fdefinition 'padx))
#<ACLMOP:FUNCALLABLE-STANDARD-CLASS STANDARD-GENERIC-FUNCTION>
CTK(58): (class-precedence-list *)
(#<ACLMOP:FUNCALLABLE-STANDARD-CLASS
STANDARD-GENERIC-FUNCTION>
#<ACLMOP:FUNCALLABLE-STANDARD-CLASS GENERIC-FUNCTION>
#<STANDARD-CLASS EXCL::DEPENDEE-MIXIN>
#<STANDARD-CLASS EXCL::PLIST-MIXIN>
#<STANDARD-CLASS ACLMOP:METAOBJECT>
#<STANDARD-CLASS ACLMOP:FUNCALLABLE-STANDARD-OBJECT>
#<STANDARD-CLASS STANDARD-OBJECT> #<BUILT-IN-CLASS FUNCTION>
#<BUILT-IN-CLASS T>)
But I missed the tempting generic-function, which happens not to be
listed in the dictionary of objects.
thx
kt
--
Home? http://tilton-technology.com
Cells? http://www.common-lisp.net/project/cells/
Cello? http://www.common-lisp.net/project/cello/
Why Lisp? http://alu.cliki.net/RtL%20Highlight%20Film
Your Project Here! http://alu.cliki.net/Industry%20Application
Kenny Tilton <·······@nyc.rr.com> wrote:
> Is there a CL-standard way to distinguish between a generic function and
> non-GF? Nothing in CLHS jumps out at me as a direct or indirect
(typep (fdefinition 'foo) 'generic-function)
Cheers,
-- Nikodemus "Not as clumsy or random as a C++ or Java.
An elegant weapon for a more civilized time."
Am Fri, 02 Jul 2004 15:10:03 GMT schrieb Kenny Tilton <·······@nyc.rr.com>:
> Is there a CL-standard way to distinguish between a generic function and
> non-GF? Nothing in CLHS jumps out at me as a direct or indirect
> solution, but I think my imagination must be failing me.
How about:
(defun generic-function-p (sym)
(and (functionp sym)
(typep (symbol-function sym) 'generic-function)))
--
,,
\../ / <<< The LISP Effect
|_\\ _==__
__ | |bb| | _________________________________________________
From: Christophe Rhodes
Subject: Re: ANSI CL way to determine GF-ness?
Date:
Message-ID: <sqk6xm3y1t.fsf@cam.ac.uk>
Thomas Schilling <······@yahoo.de> writes:
> Am Fri, 02 Jul 2004 15:10:03 GMT schrieb Kenny Tilton <·······@nyc.rr.com>:
>
>> Is there a CL-standard way to distinguish between a generic function
>> and non-GF? Nothing in CLHS jumps out at me as a direct or indirect
>> solution, but I think my imagination must be failing me.
>
> How about:
>
> (defun generic-function-p (sym)
> (and (functionp sym)
> (typep (symbol-function sym) 'generic-function)))
I don't really know what you were thinking here, but it appears
confused. This function returns NIL on non-functions, and signals an
error on functions... probably not what was intended.
(typep fun 'generic-function)
or
(typep (fdefinition function-name) 'generic-function)
are probably what was wanted.
Christophe
--
http://www-jcsu.jesus.cam.ac.uk/~csr21/ +44 1223 510 299/+44 7729 383 757
(set-pprint-dispatch 'number (lambda (s o) (declare (special b)) (format s b)))
(defvar b "~&Just another Lisp hacker~%") (pprint #36rJesusCollegeCambridge)
In article <··············@cam.ac.uk>,
Christophe Rhodes <·····@cam.ac.uk> wrote:
> Thomas Schilling <······@yahoo.de> writes:
>
> > Am Fri, 02 Jul 2004 15:10:03 GMT schrieb Kenny Tilton <·······@nyc.rr.com>:
> >
> >> Is there a CL-standard way to distinguish between a generic function
> >> and non-GF? Nothing in CLHS jumps out at me as a direct or indirect
> >> solution, but I think my imagination must be failing me.
> >
> > How about:
> >
> > (defun generic-function-p (sym)
> > (and (functionp sym)
> > (typep (symbol-function sym) 'generic-function)))
>
> I don't really know what you were thinking here, but it appears
> confused. This function returns NIL on non-functions, and signals an
> error on functions... probably not what was intended.
> (typep fun 'generic-function)
> or
> (typep (fdefinition function-name) 'generic-function)
> are probably what was wanted.
>
> Christophe
I think what was intended was:
(defun generic-function-p (x)
(or (typep x 'generic-function)
(and (typep x '(or symbol cons)) ; handles (setf <sym>)
(typep (fdefinition x) 'generic-function))))
--
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
I wrote without much pondering:
>>> > How about:
>>> >
>>> > (defun generic-function-p (sym)
>>> > (and (functionp sym)
>>> > (typep (symbol-function sym) 'generic-function)))
>>>
>>> I don't really know what you were thinking here, but it appears
>>> confused. This function returns NIL on non-functions, and signals an
>>> error on functions... probably not what was intended.
>>> (typep fun 'generic-function)
>>> or
>>> (typep (fdefinition function-name) 'generic-function)
>>> are probably what was wanted.
>>>
>>> Christophe
>>
>> I think what was intended was:
>>
>> (defun generic-function-p (x)
>> (or (typep x 'generic-function)
>> (and (typep x '(or symbol cons)) ; handles (setf <sym>)
>> (typep (fdefinition x) 'generic-function))))
>>
>
> I recently wrote some (working code) using:
>
> (do-symbols (sym p)
> (when (eql (symbol-package sym) p)
> (when (fboundp sym)
> (add-function sym pkg))
>
> and
>
> (defun add-function (sym pkg)
> (when (special-operator-p sym)
> (return-from add-function))
> (let ((doc (documentation sym 'function)))
> (push (cond
> ((typep (symbol-function sym) 'generic-function)
> (let ((gf (make-instance
> 'doc-generic-function
> :name (string-downcase (symbol-name sym))
> ...
>
Indeed I haven't tested my code. Sorry.
The major difference is that I used fboundp which works on symbols instead
of functionp which works on any object.
But Barry's solution is still better.
--
,,
\../ / <<< The LISP Effect
|_\\ _==__
__ | |bb| | _________________________________________________
Thomas Schilling wrote:
>>> (defun generic-function-p (x)
>>> (or (typep x 'generic-function)
>>> (and (typep x '(or symbol cons)) ; handles (setf <sym>)
>>> (typep (fdefinition x) 'generic-function))))
Shame on all of you! The question was about functions, not about
names of functions. Each of you should go to the blackboard and
write "A symbol is not a function." 10,000 times.
On the substance of the difference between the system classes
function and generic-function, it is worth pointing out that the
implementation is required to create a generic-function in response
to execution of a defmethod or certain other forms, but it is also
at liberty to implement _any_ or _all_ functions as generic functions.
I don't know of any implementation that does this, of course.