I have a small program that demonstrates some surprising behavior regarding 
`prop:custom-print-quotable 'never`. Perhaps it could be considered a bug, 
although I haven't seen anything in the docs that this violates. I've found 
that

1. When I call `(println y)`, my `custom-display` is called first. And what 
I do in `custom-display` affects the result of `(println y)`
2. The printer is doing something with `eq?` rather than `equal?`. (Does 
this mean that constructing any new data structure, even a list, during 
printing is an anti-pattern?)

In the example below, if `(maybe-rebuild lst)` returns `(identity lst)` 
then `prop:custom-print-quotable 'never` works as I expected. But if 
`(maybe-rebuild lst)` returns `(apply list lst)` which is a list that is 
equal? but not eq? to the original list, then `prop:custom-print-quotable 
'never` surprises me.

#lang racket

(require racket/struct)

(struct my-struct (item) #:transparent
  #:property prop:custom-print-quotable 'never)

(define (go port mode val)
  (let ([proc (make-constructor-style-printer
               (λ (me) 'my-class%)
               (λ (me) (list val)))])
    (proc (void) port mode)))

(define (maybe-rebuild lst)
  ; Works as expected if we return the same list
  #;(identity lst)
  ; But this breaks prop:custom-print-quotable 'never
  (apply list lst))

(define my-class%
  (class* object% (printable<%>)
    (super-new)
    (init-field content)
    (define/public (custom-print port mode)
      (go port mode content))
    (define/public (custom-write port)
      (go port #t content))
    (define/public (custom-display port)
      (go port #f (maybe-rebuild content)))))

(define x (list 'CONTENT (my-struct '(1 a))))
(println x)
(define y (new my-class% [content x]))
(println y)


-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/a8205ac0-bb35-4ffe-aa5e-56377a80cf24%40googlegroups.com.

Reply via email to