tags:

views:

163

answers:

3

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?

+1  A: 

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.

Nick D
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...)
Eli Barzilay
Eli, I agree. And by saying `override` I also mean `re-define`.
Nick D
A: 

If you don't want to replace print you might try out SRFI-28 instead:

http://srfi.schemers.org/srfi-28/srfi-28.html

grettke
+2  A: 

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

Eli Barzilay