[previous] [up] [next]     [contents] [index]
Next: DrScheme's Menus Up: General DrScheme Previous: Locating Errors

Console IO

Many people who have used read in other Scheme implementations find the read primitive in DrScheme odd. This section attempts to explain what is happening.

One of the enhancements in DrScheme is that it carefully differentiates the i/o of the program from the final value(s) it returns. In a typical Scheme implementation, all these interactions occur in the same visual space, which can be confusing, can lead to incoherent i/o state, and produces illegible transcripts. In DrScheme, all (screen) i/o creates its own separate i/o panel (and uses separate color cues) to distinguish i/o from the results of expression evaluation.

Unfortunately, this interaction is not always obvious. Here's a simple example. Consider the program

  (define v (read))
  v

Executing this (by typing it into the definitions window and clicking on the execute button) yields

  --------------------------------------------------------------------
  |_                                                                 |
  --------------------------------------------------------------------

with the cursor at the spot marked by the underscore. The mouse pointer, confusingly, turns into a watch cursor, even when you move it over the panel. This is okay. Click the mouse inside the box and type. This will be read by DrScheme. If you were to type (1 2) and hit enter, you would see

  --------------------------------------------------------------------
  |(1 2)                                                             |
  --------------------------------------------------------------------
  (1 2)
  > _

The second (1 2) is the value of v being printed out.

Here is a more confusing example. Consider the program

  (define v (read))
  (display v)
  v

and provide the same input. Executing this produces

  --------------------------------------------------------------------
  |(1 2)                                                             |
  |(1 2)                                                             |
  --------------------------------------------------------------------
  (1 2)
  > _

The display has written its output beneath the input you typed. However, say you were to enter this program one line at a time in the interactions window instead. You would get

  > (define v read)
  --------------------------------------------------------------------
  |                                                                  |
  --------------------------------------------------------------------

If you type in (1 2) followed by return, you get

  > (define v read)
  --------------------------------------------------------------------
  |(1 2)                                                             |
  --------------------------------------------------------------------
  >

Next, (display v):

  > (display v)
  --------------------------------------------------------------------
  |(1 2)                                                             |
  --------------------------------------------------------------------
  > _

Now enter v:

  > v
  (1 2)
  > _

This example has the same program, but very different behavior! This is because Scheme cannot determine the extent of a top-level's interaction. Hence, each expression is treated as if it were a program on its own.


[previous] [up] [next]     [contents] [index]
Next: DrScheme's Menus Up: General DrScheme Previous: Locating Errors

PLT