Hi Richard,

On 2014-09-24 21:34, Richard wrote:
> If I have an object that references itself, like for example...
> 
> (define v (vector 0))
> (vector-set! v 0 v)
> 
> and I print it, chicken goes -understandably- into an infinite loop.
> 
> Is there a way to prevent this, or is there something like
> define-record-printer for non-record objects.

FWIW there are `display` and `write` procedures in the scheme.write
library of the r7rs egg that handle such objects. That module is
self-contained and can be used without pulling in the rest of r7rs:

    #;1> (use scheme.write)
    ; loading /home/evanh/.chickens/master/lib/chicken/7/scheme.write.import.so 
...
    ; loading /home/evanh/.chickens/master/lib/chicken/7/chicken.import.so ...
    ; loading /home/evanh/.chickens/master/lib/chicken/7/scheme.write.so ...
    #;2> (define v (vector 0))
    #;3> (vector-set! v 0 v)
    #;4> (display v)
    #0=#(#0#)

Even so, csi's built-in writer will still loop on `v` if you don't
explicitly print it. Maybe that behavior should also change when
scheme.write is loaded, hmmm...

Evan

_______________________________________________
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users

Reply via email to