From: Barry Margolin
Subject: Re: How to test on circular structures,structures and instances of classes
Date:
Message-ID: <qXgb2.70$g34.4617@burlma1-snr1.gtei.net>
In article <·················@akam.be>, Marc Mertens <········@akam.be> wrote:
>1. How can one test if a object is not printable because of
>circularity?
LIST-LENGTH will return NIL if the list is circular in the CDR direction.
But there's nothing that tests whether it's circular in the CAR direction,
i.e. infinitely nested.
> Example : (setf a '(1 2 3 4))
> (setf (cdr a) a)
> produces a circular object because it refers
>itself (you can do this
> also with structures , .... ) which can't be
>printed because print goes in
> an infinite loop.
> Can one in general test if these objects are
>circular ?
No, there's nothing built-in that tests whether a structure is infinitely
nested.
You can set *PRINT-CIRCULAR* to T and the printer will check, using #n= and
#n# notation to indicate circular references.
>2. How can one test if a object is a structure?
> Example : (defstruct s-a ....)
> (setf a (make-s-a ...))
> How can I test that a is a structure (without
>causing lisp errors).
(typep (class-of a) 'structure-class)
>3. How can one test if a object is a instance of a class.
> Example : (defclass c-a ....)
> (setf a (make-instance 'c-a ...))
> How can I test if a is a instance of a class
>(without causing lisp errors).
(typep a 'standard-object)
--
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Don't bother cc'ing followups to me.
From: Marc Mertens
Subject: Re: How to test on circular structures,structures and instances of classes
Date:
Message-ID: <366EECBB.444A8ADA@akam.be>