Difference between Print and Display

20,975

Solution 1

The thing is that programs can expect certain output formats from write and display. In PLT, it is possible to change how they behave, but a little involved to do so. This is intentional, since doing such a change can have dramatic and unexpected result.

OTOH, changing how print behaves is deliberately easy -- just see the current-print documentation. The idea is that print is used for debugging, for presenting code to you in an interactive REPL -- not as a tool that you will rely on for output that needs to be formatted in a specific way. (BTW, see also the "~v" directive for format, printf, etc.)

Solution 2

You are free to override print function. If you want to override standardized functions, for example the write, you must obey to the output standard, otherwise code that use it will possibly break.

About display and write:

The Scheme Programming Language, 3rd edition, pg. 178

(display obj)
(display obj output-port)
returns unspecified

display is similar to write but prints strings and characters found within obj directly. Strings are printed without quotation marks or slashes, and characters are printed without #\ notation. For example, both (display "(a b c)") and (display '("a b" c)) would print (a b c). Because of this, display should not be used to print objects that are indended to be read with read. display is useful primarily for printing messages, with obj most often being a string.

Share:
20,975

Related videos on Youtube

unj2
Author by

unj2

.

Updated on June 27, 2020

Comments

  • unj2
    unj2 almost 4 years

    PLT Scheme's documentation says:

    The rationale for providing print is that display and write both have relatively standard output conventions, and this standardization restricts the ways that an environment can change the behavior of these procedures. No output conventions should be assumed for print, so that environments are free to modify the actual output generated by print in any way.

    Could somebody please explain what that means for a noob and how is print and display different?

    • mistertodd
      mistertodd almost 15 years
      It should be noted that it's not a question related to PLT Scheme, but a generic terminology question: is there a conceptual difference between "display" and "write"?
  • Eli Barzilay
    Eli Barzilay almost 15 years
    In most modern Scheme implementations, PLT included, you cannot just "override" a function that you didn't define. IOW, you can write your own definition of write or display, but it will not affect any code except for your own code. This is an important principle, otherwise DrScheme (for example) would break left and right. (That chaos is roughly how Emacs is made...)
  • Nick Dandoulakis
    Nick Dandoulakis almost 15 years
    Eli, I agree. And by saying override I also mean re-define.

Related