From: Eli Bendersky
Subject: printing circular data structures
Date: 
Message-ID: <e0ef3fee-c7dd-482e-883c-7ef0f667232a@s8g2000prg.googlegroups.com>
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.)

Thanks
Eli

From: Eli Bendersky
Subject: Re: printing circular data structures
Date: 
Message-ID: <d047bc8e-d8eb-4966-8346-ef232a4ae8d7@r60g2000hsc.googlegroups.com>
On Nov 30, 12:11 pm, Eli Bendersky <······@gmail.com> 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.)
>

Ouch, sorry for bothering the newsgroup. Had I only tried one another
google search, I would quickly turn up with:

(setf *print-circle* t)

I wish it was possible to retract Google Groups messages withing some
short time of posting :-)

Sorry again,
Eli
From: Øyvin Halfdan Thuv
Subject: Re: printing circular data structures
Date: 
Message-ID: <slrnfkvq5g.rh6.oyvinht@decibel.pvv.ntnu.no>
On 2007-11-30, Eli Bendersky <······@gmail.com> wrote:
> On Nov 30, 12:11 pm, Eli Bendersky <······@gmail.com> 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.)
>>
>
> Ouch, sorry for bothering the newsgroup. Had I only tried one another
> google search, I would quickly turn up with:
>
> (setf *print-circle* t)

Or:

(let ((*print-circle* t))
  ... your code here ...
 )

and the rest of your CL-environment will not be affected.

-- 
Oyvin
From: Zach Beane
Subject: Re: printing circular data structures
Date: 
Message-ID: <m3abovhkpx.fsf@unnamed.xach.com>
Øyvin Halfdan Thuv <·······@localhost.localdomain> writes:

> On 2007-11-30, Eli Bendersky <······@gmail.com> wrote:
[snip]
>>
>> (setf *print-circle* t)
>
> Or:
>
> (let ((*print-circle* t))
>   ... your code here ...
>  )
>
> and the rest of your CL-environment will not be affected.

I sometimes get confused by the REPL behavior when lexically binding
printer control variables until I remember that they will have no
effect on the REPL's printing of the return value, so I have to put a
PRINT within the LET and return nothing in particular.

Zach
From: Øyvin Halfdan Thuv
Subject: Re: printing circular data structures
Date: 
Message-ID: <slrnfkvps4.rh6.oyvinht@decibel.pvv.ntnu.no>
On 2007-11-30, Eli Bendersky <······@gmail.com> 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