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

From: Williams, M. Douglas (M.DOUGLAS.WILLIAMS at saic.com)
Date: Tue May 8 10:51:38 EDT 2007

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.  In
each of them I am using the PLoT collection to generate an image-snip%.
[I have also included the files.]

 

 

test-1.ss

 

(require (lib "plot.ss" "plot"))

 

(printf "This is a plot of the sine function~n")

(plot (line sin))

 

When run under DrScheme, this prints the text and displays the plot.
Under MrEd (mred -r test-1.ss), the text is displayed, but the plot
isn't (not even textually).  I assume this is the difference between the
behaviors of the respective REPLs.  [No biggie here, the IDE REPL
behavior is richer than a pure run-time REPL.]

 

test-2.ss

 

(require (lib "plot.ss" "plot"))

 

(printf "This is a plot of the sine function~n")

(print (plot (line sin)))

(newline)

 

Under DrScheme, this has the same output as test-1.ss.  Under MrEd (mred
-r test-2.ss, the text is displayed and the plot is displayed textually
as #<struct:object:2d-view%>.  Based on an answer by Ryan Culpepper to a
previous e-mail of mine, I assume this is due to the differences between
the print routines in DrScheme and MrEd.

 

test-3.ss

 

(require (lib "plot.ss" "plot"))

 

(printf "This is a plot of the sine function~n")

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

 

This has the same behavior as test-2.ss.  I just wanted to show that,
under DrScheme, printf also displayed image-snip% instances.

 

test-4.ss

 

(require (lib "plot.ss" "plot"))

 

(define (test-4)

  (parameterize

      ((current-output-port

        (open-output-text-editor text)))

    (printf "This is a plot of the sine function~n")

    (print (plot (line sin)))

    (newline)))

 

(define frame

  (instantiate frame% ("Test 4")))

 

(define canvas (instantiate editor-canvas% (frame)

                 (min-width 500)

                 (min-height 450)

                 (style '(no-hscroll hide-vscroll))))

 

(define text (instantiate text% ()))

 

(send canvas set-editor text)

 

(send frame show #t)

 

(test-4)

 

This creates a separate window for the output.  The results in that
window are the same as for test-2.ss - i.e. the plot is printed under
DrScheme and just a textually representation under MrEd..  I had hoped
that the open-output-text-editor produced a port with the same behavior
across DrScheme and MrEd, but it doesn't.  [This also seems to validate
Ryan's earlier comments on the behavior of the print, etc in DrScheme.]

 

test-5.ss

 

(require (lib "plot.ss" "plot"))

 

(define (test-5)

  (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)))))

 

(define frame

  (instantiate frame% ("Test 4")))

 

(define canvas (instantiate editor-canvas% (frame)

                 (min-width 500)

                 (min-height 450)

                 (style '(no-hscroll hide-vscroll))))

 

(define text (instantiate text% ()))

 

(send canvas set-editor text)

 

(send frame show #t)

 

(test-5)

 

This one surprised me.  This is the same as test-4.ss, but uses printf
instead of print to display the plot.  This displays the image-snip%
textually under both DrScheme and MrEd.  [That's why I included
test-3.ss.]

 

 

It would be nice to have consistent graphical output in both graphical
execution environments.  I think I understand what is going on 'under
the cover' - at some level DrScheme and MrEd have different printing
routines and DrScheme's support write-special and MrEd's don't.
[Although test-5.ss still has me confused.]  Is it possible to get the
DrScheme behavior in MrEd?  [For example, I had hoped that
open-output-text-editor would do that for me.]

 

One other thing is the behavior under MzScheme.  It punts because of a
dynamic require for #%mred-kernel failing - which I understand.  But,
would it be possible to revert to the textual display of the objects in
this case?

 

Sorry for the length of the post.

 

Doug

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20070508/6310fa53/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test-5.ss
Type: application/octet-stream
Size: 575 bytes
Desc: test-5.ss
URL: <http://lists.racket-lang.org/users/archive/attachments/20070508/6310fa53/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test-1.ss
Type: application/octet-stream
Size: 103 bytes
Desc: test-1.ss
URL: <http://lists.racket-lang.org/users/archive/attachments/20070508/6310fa53/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test-2.ss
Type: application/octet-stream
Size: 122 bytes
Desc: test-2.ss
URL: <http://lists.racket-lang.org/users/archive/attachments/20070508/6310fa53/attachment-0002.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test-3.ss
Type: application/octet-stream
Size: 121 bytes
Desc: test-3.ss
URL: <http://lists.racket-lang.org/users/archive/attachments/20070508/6310fa53/attachment-0003.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test-4.ss
Type: application/octet-stream
Size: 582 bytes
Desc: test-4.ss
URL: <http://lists.racket-lang.org/users/archive/attachments/20070508/6310fa53/attachment-0004.obj>

Posted on the users mailing list.