[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] Printing circular lists
From: |
Taylor Venable |
Subject: |
Re: [Chicken-users] Printing circular lists |
Date: |
Tue, 3 Aug 2010 17:38:31 -0400 |
On Tue, Aug 3, 2010 at 4:03 PM, Jeronimo Pellegrini <address@hidden> wrote:
> I was wondering how to get Chicken to print cyclic structures
> using references to previous elements instead of looping, like
> this, for example (this is what Gauche does on the REPL, and
> what Guile's display implementation does):
>
> > a
> #0=(1 . #0#)
>
> Is there some way to configure Chicken to do that? (I've searched
> the wiki but found nothing)
If you're open to using a different method to do so, both the fmt and
srfi-38 eggs provide such a means via fmt and
write-with-shared-structure, respectively.
#;1> (use fmt)
; loading /opt/chicken/lib/chicken/5/fmt.import.so ...
; loading /opt/chicken/lib/chicken/5/srfi-1.import.so ...
; loading /opt/chicken/lib/chicken/5/srfi-13.import.so ...
; loading /opt/chicken/lib/chicken/5/srfi-69.import.so ...
; loading /opt/chicken/lib/chicken/5/extras.import.so ...
; loading /opt/chicken/lib/chicken/5/fmt.so ...
#;2> (define a (list 1 2))
#;3> (set-cdr! a a)
#;4> (fmt #f a)
"#0=(1 . #0#)"
#;1> (use srfi-38)
; loading /opt/chicken/lib/chicken/5/srfi-38.import.so ...
; loading /opt/chicken/lib/chicken/5/extras.import.so ...
; loading /opt/chicken/lib/chicken/5/srfi-38.so ...
#;2> (define a (list 1 2))
#;3> (set-cdr! a a)
#;4> (write-with-shared-structure a) (newline)
#=0(1 . #0#)
--
Taylor C. Venable
http://metasyntax.net/