[racket-dev] Custom write that pretty-prints and works well with quote?
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