Re: printing circular data structures
- From: Øyvin Halfdan Thuv <oyvinht@xxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 30 Nov 2007 10:35:48 +0000 (UTC)
On 2007-11-30, Eli Bendersky <eliben@xxxxxxxxx> wrote:
Hello,
I want to be able to print out data structures, without having the
environment blow up if the data structure is circular. One way to do
this is to limit the amount of characters the printer prints. Is this
possible in Common Lisp ?
The implementation I'm using is CLISP, though I suspect there can be a
standard way, since I want it to work for all my printing functions
(print, format, etc.)
Hi Eli,
you should look at the *print-<..>* variables:
http://www.lispworks.com/documentation/HyperSpec/Front/X_Perm_P.htm
*print-cirle* and *print-level* might be of interest for example.
You can also provide a more specific print-object method? E.g.:
(defclass my-class ()
((my-slot :accessor my-class-my-slot
:initform "the value")))
(defmethod print-object ((mc my-class) (s stream))
(format s "#MY-CLASS WITH MY-SLOT=~A~%" (my-class-my-slot mc)))
and then you will get:
CL-USER> (make-instance 'my-class)
#MY-CLASS WITH MY-SLOT=the value
CL-USER>
.... so you can basically do exactly whatever you want with the object.
--
Oyvin
.
- References:
- printing circular data structures
- From: Eli Bendersky
- printing circular data structures
- Prev by Date: Re: printing circular data structures
- Next by Date: Re: The origins of CL conditions system
- Previous by thread: Re: printing circular data structures
- Next by thread: Compilation order when compiling and loading a file
- Index(es):
Relevant Pages
|
|