[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

Common Lisp equivalent of INSTANCEP

Old Time Lisper

12/23/2015 1:12:00 AM

What type specifier or predicate should I use to determine whether CLASS-OF (and other MOP introspection) is applicable? How about in TYPECASE. The Lisp machine has INSTANCEP, but Common Lisp apparently doesn't. Maybe I'm using the wrong Google search terms, but couldn't even find a notion of a "base class," comparable to SI:VANILLA-FLAVOR. I'm designing a sort of printer/serializer that can be applied to any Lisp object.
3 Answers

Pascal J. Bourguignon

12/23/2015 12:19:00 PM

0

Old Time Lisper <mctuva4004@gmail.com> writes:

> What type specifier or predicate should I use to determine whether
> CLASS-OF (and other MOP introspection) is applicable? How about in
> TYPECASE. The Lisp machine has INSTANCEP, but Common Lisp apparently
> doesn't. Maybe I'm using the wrong Google search terms, but couldn't
> even find a notion of a "base class," comparable to SI:VANILLA-FLAVOR.
> I'm designing a sort of printer/serializer that can be applied to any
> Lisp object.


(defun instancep (object class-designator &optional environment)
(and (apply (function find-class) class-designator
(when environment (list environment)))
(typep object class-designator)))


--
__Pascal Bourguignon__ http://www.informat...
â??The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.� -- Carl Bass CEO Autodesk

Pascal J. Bourguignon

12/23/2015 12:31:00 PM

0

"Pascal J. Bourguignon" <pjb@informatimago.com> writes:

> Old Time Lisper <mctuva4004@gmail.com> writes:
>
>> What type specifier or predicate should I use to determine whether
>> CLASS-OF (and other MOP introspection) is applicable? How about in
>> TYPECASE. The Lisp machine has INSTANCEP, but Common Lisp apparently
>> doesn't. Maybe I'm using the wrong Google search terms, but couldn't
>> even find a notion of a "base class," comparable to SI:VANILLA-FLAVOR.
>> I'm designing a sort of printer/serializer that can be applied to any
>> Lisp object.
>
>
> (defun instancep (object class-designator &optional environment)
> (and (apply (function find-class) class-designator
> (when environment (list environment)))
> (typep object class-designator)))

Sorry, it's incorrect, typep should take the environment parameter too
when given. Also, find-class takes class names, not classes, so:

(defgeneric instancep (object class-designator &optional environment)
(:method (object (class-designator symbol) &optional environment)
(let ((class (apply (function find-class) class-designator
(when environment (list environment)))))
(and class
(instancep object class))))
(:method (object (class class) &optional environment)
(apply (function typep) object class
(when environment (list environment)))))


Notice that class objects can be type specifiers:

4.2.3 Type Specifiers

Type specifiers can be symbols, classes, or lists.



--
__Pascal Bourguignon__ http://www.informat...
â??The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.� -- Carl Bass CEO Autodesk

taruss

12/28/2015 7:27:00 PM

0

On Tuesday, December 22, 2015 at 5:11:44 PM UTC-8, Old Time Lisper wrote:
> What type specifier or predicate should I use to determine whether CLASS-OF (and other MOP introspection) is applicable? How about in TYPECASE. The Lisp machine has INSTANCEP, but Common Lisp apparently doesn't. Maybe I'm using the wrong Google search terms, but couldn't even find a notion of a "base class," comparable to SI:VANILLA-FLAVOR. I'm designing a sort of printer/serializer that can be applied to any Lisp object.

The "base class" is CL:STANDARD-OBJECT.
Would it be enough to use that in TYPECASE or TYPEP?
http://www.lispworks.com/documentation/HyperSpec/Body/t_std_ob.htm#stand...

You might also want to look at "Types and Classes":
http://www.lispworks.com/documentation/HyperSpec/Body...