2.5 Output Printing Styles

Many Scheme languages support a Output Syntax choice that determines how evaluation results are printed in the interactions window. This setting also applies to output generated by calling print explicitly.

The following table illustrates the difference between the different output styles:

 

Input expression

 

Constructor

 

Quasiquote

 

write

 

(cons 1 2)

 

(cons 1 2)

 

`(1 . 2)

 

(1 . 2)

 

(list 1 2)

 

(list 1 2)

 

`(1 2)

 

(1 2)

 

'(1 2)

 

(list 1 2)

 

`(1 2)

 

(1 2)

 

(list (void))

 

(list (void))

 

`(,(void))

 

(#<void>)

 

`(,(void))

 

(list (void))

 

`(,(void))

 

(#<void>)

 

(vector 1 2 3)

 

(vector 1 2 3)

 

(vector 1 2 3)

 

#(1 2 3)

 

(box 1)

 

(box 1)

 

(box 1)

 

#&1

 

(lambda (x) x)

 

(lambda (a1) ...)

 

(lambda (a1) ...)

 

#<procedure>

 

'sym

 

'sym

 

'sym

 

sym

 

(make-s 1 2)

 

(make-s 1 2)

 

(make-s 1 2)

 

#(struct:s 1 2)

 

'()

 

empty

 

`()

 

()

 

add1

 

add1

 

add1

 

#<procedure:add1>

 

(delay 1)

 

(delay ...)

 

(delay ...)

 

#<promise>

 

(regexp "a")

 

(regexp "a")

 

(regexp "a")

 

#rx"a"

The Constructor output mode treats cons, vector, and similar primitives as value constructors, rather than functions. It also treats list as shorthand for multiple cons’s ending with the empty list. Constructor output is especially valuable for beginning programmers, because output values look the same as input values.

The Quasiquote output mode is like Constructor output, but it uses quasiquote (abbreviated with `) to print lists, and it uses unquote (abbreviated with ,) to escape back to Constructor printing as needed. This mode provides the same benefit as Constructor output, in that printed results are expressions, but it is more convenient for many kinds of data, especially data that represents expressions.

The print output mode corresponds to traditional Scheme printing via the print procedure, which defaults to write-like printing, as shown in the last column.

DrScheme also sets the global-port-print-handler in order to customize a few aspects of the printing for all of these modes, namely printing the symbol quote as a single tick mark (mutatis mutandis for quasiquote, unquote, and unquote-splicing), and to print rational real numbers using a special snip% object that lets the user choose between improper fractions, mixed fractions, and repeating decimals.