[plt-scheme] Graphics Behavior Differences Between DrScheme and MrEd

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Tue May 8 17:45:04 EDT 2007

At Tue, 8 May 2007 07:51:38 -0700, "Williams, M. Douglas" wrote:
> I am trying to understand the behavior of graphics output between (some
> of) the various run/display mechanisms available under PLT Scheme.  In
> particular, I want to understand the differences between running some
> code under DrScheme versus MrEd.  Another objective is to see if there
> is some way to get the behavior to be consistent across the two.

The main difference that you're seeing is that DrScheme installs a
print handler via `global-port-print-handler'. If you add

 (global-port-print-handler (lambda (value port)
                              (write value port)))

to the program, then it behaves the same in DrScheme as MrEd.

DrScheme also installs write and display handlers for the ports
associated with the interaction window. That's why

> (printf "~a~n" (plot (line sin)))

still shows the graph under DrScheme. But there's no global
write/display handler (by design), which is why

>   (parameterize
>       ((current-output-port
>         (open-output-text-editor text)))
>     (printf "This is a plot of the sine function~n")
>     (printf "~a~n" (plot (line sin)))))

behaves the same in DrScheme as MrEd. If you use "~v" instead of "~a",
then even the last example shows the graph in DrScheme.

DrScheme's print handler is in "collects/drscheme/private/language.ss".
Mostly, it just calls `pretty-print' after installing hooks to detect

      (lambda ()
        (parameterize ([pretty-print-columns 'infinity])
          (pretty-print value port))))

and `setup-printing-parameters' is the interesting part:

  (define (setup-printing-parameters thunk settings width)
      (parameterize ([pretty-print-columns width]
                      (lambda (value display? port)
                          ;; only hook when `write-special' is available:
                          [(not (port-writes-special? port)) #f]
                          [(is-a? value snip%) 1]
                      (lambda (value display? port)
                          [(is-a? value snip%)
                           (write-special value port)



Posted on the users mailing list.