2.5 Output Printing Styles

Many Racket 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 print style is the normal Racket output style. The following table illustrates the other 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 is similar to Rackets normal print mode, except that even quotable are still printed with constructors, constructor functions and forms are used to approximate some otherwise unprintable values. For example, Constructor output prints a procedure in a lambda form. For output to a graphical context, rational numbers are printed using a special snip% object that lets the user choose between improper fractions, mixed fractions, and repeating decimals.

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.

The write output mode corresponds to traditional Scheme printing via the write procedure. For example, lists print by parenthesizing the printed form of the list elements, without a leading quote mark or a constructor name.

The print output mode corresponds to Racket’s default printing via the print procedure. Output via print is further configurable through run-time settings, such as the print-as-expression parameter, and it may be adjusted by a #lang-specified language. For example, the scheme language sets the print-as-expression parameter to #f, which essentially makes print mode act like write mode.

The Constant Style option, when present, controls how true, false, and empty print; for the booleans, it determines if there is a # prefix and for the empty list, determines if it prints as empty or '().

For any of the output styles, DrRacket sets the global-port-print-handler so that the print procedure produces output as selected.