[racket] print/pretty-print weirdness

From: Christopher (ultimatemacfanatic at gmail.com)
Date: Tue Nov 5 14:09:41 EST 2013

I'm experiencing some weirdness with print and pretty-print.

First of all, can someone please explain why these print the same thing:

> (print 'hello (current-output-port) 0)
'hello
> (print 'hello (current-output-port) 1)
'hello

But these do not:

> (pretty-print 'hello (current-output-port) 0)
'hello
> (pretty-print 'hello (current-output-port) 1)
hello

(notice the bottom line has no quote in front of the symbol)

It seems to me that (print 'hello (current-output-port) 1) should not print with a single-quote in front of the symbol, but it does, as you can see above.


Consider this:

#lang racket

(define allow-quoted #t)

(define printable-unquoted<%>
  (interface* []
    [[prop:custom-print-quotable 'never]
     [prop:custom-write 
       (lambda (obj port mode)
         (cond
           [{eq? mode #t} (send obj custom-write port)]
           [{eq? mode #f} (send obj custom-display port)]
           [(or {= mode 0} allow-quoted) (send obj custom-print port)]
           [{= mode 1} {error {string-append "printable-unquoted<%> object "
                                      "called with depth of 1" }}]))]]
     custom-write custom-display custom-print ))

(define test-printable%
  (class* object% [printable-unquoted<%>]
    (super-make-object)
    
    (define/public [custom-print port]
      {display "(make-object test-printable%)" port} )
    
    (define/public [custom-write port]
      {display "|;-)" port} )
    
    (define/public [custom-display port]
      {custom-write port} ))) 

(struct test-printable []
  #:property prop:custom-print-quotable 'never
  #:methods gen:custom-write
  [(define [write-proc strct port arg]
     {fprintf port "(test-printable ~v)" {vector (new test-printable%)}} )])


{print {test-printable}}

If I run it with (define allow-quoted #t) then the result is:

(test-printable '#((make-object test-printable%)))

Notice that the declared unquotable object is printed in the middle of a quoted vector!!

If I set allow-quoted to #f then we confirm the obvious:

(test-printable '#(. . printable-unquoted<%> object called with depth of 1

Can anyone tell me why my prop:custom-print-quotable 'never is not being respected on my class instance?

Thanks,

Christopher
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20131105/401683e2/attachment.html>

Posted on the users mailing list.