[racket-dev] Custom write that pretty-prints and works well with quote?

From: Neil Toronto (neil.toronto at gmail.com)
Date: Mon Jul 9 11:39:04 EDT 2012

Yes! And `make-tentative-pretty-print-output-port' is helpful mostly 
because grepping for it in the source led me to "racket/set.rkt", which 
is like an extended example.

Thanks!
Neil ⊥

On 07/08/2012 09:17 AM, Matthew Flatt wrote:
> Do `prop:custom-print-quotable' and/or
> `make-tentative-pretty-print-output-port' from `racket/pretty' help?
>
> At Sat, 07 Jul 2012 11:40:49 -0700, Neil Toronto wrote:
>> I've got an array structure like so:
>>
>> (struct: (A) strict-array ([shape : (Listof Index)]
>>                              [data : (Vectorof A)])
>>
>> Say I have this value:
>>
>>       (strict-array '(2 2) #(1 2 3 4))
>>
>> I want it to print like this at the REPL:
>>
>>       #<strict-array '(2 2) '[[1 2] [3 4]]>
>>
>> If there's not enough room, I want this:
>>
>>       #<strict-array
>>         '(2 2)
>>         '((1 2) (3 4))>
>>
>> If it happens to be in a list, I want this:
>>
>>       (list #<strict-array '(2 2) '[[1 2] [3 4]]>)
>>
>> and definitely NOT '(#<strict-array '(2 2) '[[1 2] [3 4]]>) because the
>> inner quotes are confusing.
>>
>> How do I do that with prop:custom-write? The only way I've found so far
>> to get nicely formatted output is to write/display/print a list, but
>> then the quotes get messed up. I haven't found a way to keep the REPL
>> from quoting lists of structs, except to go with the default printer,
>> which flattens arrays, which makes them hard to read.
>>
>> This is frustrating.
>>
>> Neil ⊥
>> _________________________
>>    Racket Developers list:
>>    http://lists.racket-lang.org/dev



Posted on the dev mailing list.