[racket-dev] image snips and pretty-print (#lang htdp/bsl and snips)

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Thu Sep 1 17:13:14 EDT 2011

Maybe something like this is what you want (but I always get lost in
the multitude of handlers so this might not be quite the right place
to put this code).

diff --git a/collects/htdp/bsl/runtime.rkt b/collects/htdp/bsl/runtime.rkt
index d612aad..2865445 100644
--- a/collects/htdp/bsl/runtime.rkt
+++ b/collects/htdp/bsl/runtime.rkt
@@ -43,18 +43,23 @@
     (parameterize ([pretty-print-print-hook
                     (let ([oh (pretty-print-print-hook)])
                       (λ (val display? port)
-                        (if (and (not (port-writes-special? port))
-                                 (is-image? val))
-                            (begin (display img-str port)
-                                   (string-length img-str))
-                            (oh val display? port))))]
+                        (cond
+                          [(is-image? val)
+                           (if (port-writes-special? port)
+                               (write-special val port)
+                               (display img-str port))]
+                          [else
+                           (oh val display? port)])))]
                    [pretty-print-size-hook
                     (let ([oh (pretty-print-size-hook)])
                       (λ (val display? port)
-                        (if (and (not (port-writes-special? port))
-                                 (is-image? val))
-                            (string-length img-str)
-                            (oh val display? port))))])
+                        (cond
+                          [(is-image? val)
+                           (if (port-writes-special? port)
+                               1
+                               (string-length img-str))]
+                          [else
+                           (oh val display? port)])))])
       (thunk)))
   (current-print
    (lambda (v)

Robby

On Thu, Sep 1, 2011 at 3:22 PM, Danny Yoo <dyoo at cs.wpi.edu> wrote:
> How are image snips and pretty-print supposed to interact?
>
>
> I've isolated the bug that's been preventing image snips from printing
> in something like:
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> #lang htdp/bsl
> (require 2htdp/image)
> (circle 20 'solid 'green)
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>
>
> From what I can tell, the print-convert-handler is doing the right
> thing in leaving the image alone, but then the image snip gets printed
> via pretty-print, and from what I see in:
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> #lang racket/base
> (require 2htdp/image
>         racket/pretty)
>
> (write (circle 20 'solid 'green))
> (newline)
> (print (circle 20 'solid 'green))
> (newline)
> (pretty-print (circle 20 'solid 'green))
> (newline)
> (pretty-write (circle 20 'solid 'green))
> (newline)
> (pretty-display (circle 20 'solid 'green))
> (newline)
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>
>
> None of the pretty functions like image snips and print them out
> textually rather than graphically!
>
> As far as I can tell, pretty-print appears to be hardcoded to deal
> with text, not snips.  Is that true?
>
>
>
>
> If I comment out the setting of the current-print parameter in htdp/bsl/runtime,
>
> ##################################################################
> diff --git a/collects/htdp/bsl/runtime.rkt b/collects/htdp/bsl/runtime.rkt
> index d612aad..f3c96a1 100644
> --- a/collects/htdp/bsl/runtime.rkt
> +++ b/collects/htdp/bsl/runtime.rkt
> @@ -56,7 +56,7 @@
>                             (string-length img-str)
>                             (oh val display? port))))])
>       (thunk)))
> -  (current-print
> +  #;(current-print
>    (lambda (v)
>      (unless (void? v)
>        (define converted (print-convert v))
> ##################################################################
>
>
>
> then the program:
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> #lang htdp/bsl
> (require 2htdp/image)
> (circle 20 'solid 'green)
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>
> behaves properly in DrRacket and prints out fine.
> _________________________________________________
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/dev
>



Posted on the dev mailing list.