I'm seeing some bad behavior from make-constructor-style-printer when
there are lists mixed in with the structs. It seems to switch from print mode to
write mode when going under a list. Whereas the default printer for transparent structs gets this right. The following program demonstrates the difference/problem.
Any thoughts on how to get the make-constructor-style-printer to behave
properly?
#lang racket
(require racket/struct)
(struct Int1 (value) #:transparent)
(struct Prim1 (op arg*) #:transparent)
(struct Int2 (value) #:transparent
#:methods gen:custom-write
[(define write-proc
(make-constructor-style-printer
(lambda (obj) 'Int2)
(lambda (obj) (list (Int2-value obj)))))])
(struct Prim2 (op arg*) #:transparent
#:methods gen:custom-write
[(define write-proc
(make-constructor-style-printer
(lambda (obj) 'Prim2)
(lambda (obj) (list (Prim2-op obj) (Prim2-arg* obj)))))])
(define p1 (Prim1 '+ (list (Int1 1) (Int1 2))))
(print p1)(newline)
(define p2 (Prim2 '+ (list (Int2 1) (Int2 2))))
(print p2)(newline)
The output is:
(Prim1 '+ (list (Int1 1) (Int1 2)))
(Prim2 '+ '(#<Int2: 1> #<Int2: 2>))
-Jeremy