Re: [Chicken-users] Printing recursive objects
On Wed, 24 Sep 2014 16:00:29 -0700 Evan Hanson ev...@foldling.org wrote: 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 Hello Jason and Evan, Thanks for a solution and interesting background information. Richard ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
[Chicken-users] Printing recursive objects
Hello Chickens, 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. thank you, Richard ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Printing recursive objects
guile knows how to handle this: scheme@(guile-user) (define v (vector 0)) scheme@(guile-user) (vector-set! v 0 v) scheme@(guile-user) v $2 = #(#0#) It can even read the self-referencing syntax, IIRC. I know there's discussion of using Tortoise and Hare to break cycles in this situation, but what guile does seems more sophisticated. On Wed, Sep 24, 2014 at 5:34 PM, Richard plui...@freeshell.de wrote: Hello Chickens, 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. thank you, Richard ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Printing recursive objects
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