PLT Scheme's documentation says:
The rationale for providing printis that display and write bothhave relatively standard outputconventions, and this standardizationrestricts the ways that an environmentcan change the behavior of theseprocedures. No output conventionsshould be assumed for print, so thatenvironments are free to modify theactual output generated by print inany way.
Could somebody please explain what that means for a noob and how is print and display different?
Best Answer
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.)
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 writebut prints strings and charactersfound within obj directly. Stringsare printed without quotation marks orslashes, and characters are printedwithout #\ 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 objectsthat are indended to be read withread. display is useful primarily for printing messages, withobj most often being a string.
If you don't want to replace print you might try out SRFI-28 instead:
http://srfi.schemers.org/srfi-28/srfi-28.html
In Python, the print() function is primarily used for debugging and displaying simple text output in the console. It can be used to display the value of a variable, print a message to the user, or log information about the program's execution. The output of print() is often unformatted and lacks visual appeal.
On the other hand, the display() function is typically used in data analysis and visualization to display data in a more organized and aesthetically pleasing format. It is often used in Jupyter notebooks and other interactive environments to show data frames, plots, charts, and other types of graphical representations. The display() function can also be used to format and stylize the output of a data frame or other data structure.
To summarize, print() is primarily used for debugging and displaying simple text output, while display() is used for displaying data in a more organized and visually appealing format, particularly in data analysis and visualization contexts.
ex:print(dataframe)enter image description here
display(dataframe)enter image description here