* SRFI 9's default printer doesn't handle cyclic data structures
@ 2011-07-26 3:33 Chris K. Jester-Young
2011-07-26 3:45 ` nalaginrut
2011-07-26 4:56 ` nalaginrut
0 siblings, 2 replies; 3+ messages in thread
From: Chris K. Jester-Young @ 2011-07-26 3:33 UTC (permalink / raw)
To: guile-devel
[-- Attachment #1: Type: text/plain, Size: 1135 bytes --]
[Crossposted from bug-guile@ since my message isn't posting there. :-(]
Hi there,
I've been playing around with Guile's implementation of SRFI 45 (which
uses SRFI 9), and have noticed something interesting: if you run the
following code in the REPL, printing out the value of the promise will
cause a stack overflow:
(use-modules (srfi srfi-45))
(define promise (delay promise))
(force promise)
#<promise val: module/ice-9/format.scm:38:0: In procedure format:
module/ice-9/format.scm:38:0: Throw to key `vm-error' with args `(vm-run "VM: Stack overflow" ())'.
However, if I change the SRFI 45 code to use Guile's native records,
it prints correctly:
#<promise val: #<value tag: eager proc: #-1#>>
For reproducibility, I attached the diff to make SRFI 45 use Guile
native records.
So, it seems like SRFI 9's record printer doesn't handle cycles in the
record data very well. Unfortunately I don't know how to fix this (I
tried looking at the printer for Guile's native records, but couldn't
figure out what made it special enough to handle cycles correctly), so
no fix is attached.
Many thanks,
Chris.
[-- Attachment #2: srfi-45.diff --]
[-- Type: text/x-diff, Size: 1207 bytes --]
--- module/srfi/srfi-45.scm 2011-02-08 22:38:34.000000000 -0500
+++ module/srfi/srfi-45.scm 2011-07-23 20:24:51.000000000 -0400
@@ -37,15 +37,21 @@
lazy
force
eager)
- #:replace (delay force)
- #:use-module (srfi srfi-9))
+ #:replace (delay force))
-(define-record-type promise (make-promise val) promise?
- (val promise-val promise-val-set!))
+(define <promise> (make-record-type "promise" '(val)))
+(define make-promise (record-constructor <promise>))
+(define promise? (record-predicate <promise>))
+(define promise-val (record-accessor <promise> 'val))
+(define promise-val-set! (record-modifier <promise> 'val))
-(define-record-type value (make-value tag proc) value?
- (tag value-tag value-tag-set!)
- (proc value-proc value-proc-set!))
+(define <value> (make-record-type "value" '(tag proc)))
+(define make-value (record-constructor <value>))
+(define value? (record-predicate <value>))
+(define value-tag (record-accessor <value> 'tag))
+(define value-tag-set! (record-modifier <value> 'tag))
+(define value-proc (record-accessor <value> 'proc))
+(define value-proc-set! (record-modifier <value> 'proc))
(define-syntax lazy
(syntax-rules ()
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: SRFI 9's default printer doesn't handle cyclic data structures
2011-07-26 3:33 SRFI 9's default printer doesn't handle cyclic data structures Chris K. Jester-Young
@ 2011-07-26 3:45 ` nalaginrut
2011-07-26 4:56 ` nalaginrut
1 sibling, 0 replies; 3+ messages in thread
From: nalaginrut @ 2011-07-26 3:45 UTC (permalink / raw)
To: Chris K. Jester-Young; +Cc: guile-devel
> [Crossposted from bug-guile@ since my message isn't posting there. :-(]
>
> Hi there,
>
> I've been playing around with Guile's implementation of SRFI 45 (which
> uses SRFI 9), and have noticed something interesting: if you run the
> following code in the REPL, printing out the value of the promise will
> cause a stack overflow:
>
> (use-modules (srfi srfi-45))
> (define promise (delay promise))
> (force promise)
>
> #<promise val: module/ice-9/format.scm:38:0: In procedure format:
> module/ice-9/format.scm:38:0: Throw to key `vm-error' with args `(vm-run "VM: Stack overflow" ())'.
>
> However, if I change the SRFI 45 code to use Guile's native records,
> it prints correctly:
>
> #<promise val: #<value tag: eager proc: #-1#>>
>
> For reproducibility, I attached the diff to make SRFI 45 use Guile
> native records.
>
> So, it seems like SRFI 9's record printer doesn't handle cycles in the
> record data very well. Unfortunately I don't know how to fix this (I
> tried looking at the printer for Guile's native records, but couldn't
> figure out what made it special enough to handle cycles correctly), so
> no fix is attached.
>
> Many thanks,
> Chris.
Well, I got such a problem too. But some guy told be
set-record-type-printer! is helpful. So I just write a new printer for
my record for testing. I think it's unnecessary to change the module
since the printer is always used in REPL. :)
--
GNU Powered it
GPL Protected it
GOD Blessed it
HFG - NalaGinrut
--hacker key--
v4sw7CUSMhw6ln6pr8OSFck4ma9u8MLSOFw3WDXGm7g/l8Li6e7t4TNGSb8AGORTDLMen6g6RASZOGCHPa28s1MIr4p-x hackerkey.com
---end key---
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: SRFI 9's default printer doesn't handle cyclic data structures
2011-07-26 3:33 SRFI 9's default printer doesn't handle cyclic data structures Chris K. Jester-Young
2011-07-26 3:45 ` nalaginrut
@ 2011-07-26 4:56 ` nalaginrut
1 sibling, 0 replies; 3+ messages in thread
From: nalaginrut @ 2011-07-26 4:56 UTC (permalink / raw)
To: Chris K. Jester-Young; +Cc: guile-devel
I talked with cky on IRC. And I realized that I made a mistake.
He needs a cycle-printer. But in my case, I just want to avoid a cycle
printing.
So that's fine.
--
GNU Powered it
GPL Protected it
GOD Blessed it
HFG - NalaGinrut
--hacker key--
v4sw7CUSMhw6ln6pr8OSFck4ma9u8MLSOFw3WDXGm7g/l8Li6e7t4TNGSb8AGORTDLMen6g6RASZOGCHPa28s1MIr4p-x hackerkey.com
---end key---
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-07-26 4:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-26 3:33 SRFI 9's default printer doesn't handle cyclic data structures Chris K. Jester-Young
2011-07-26 3:45 ` nalaginrut
2011-07-26 4:56 ` nalaginrut
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).