Search code examples
stringoutputschemeracketquotation-marks

How to run a Racket program without output being quoted?


I have a basic Racket program:

hello.rkt:

(write "Hello, World!")

When I run it with racket -f hello.rkt, I get the following output:

"Hello, World!"

Is there a special compiler flag, or special version of "write/print" that removes the quotes from string output, so that it shows:

Hello, World!

Solution

  • The write function is the dual to read: it outputs (or at least attempts to output) datums that could be read back in to produce the original value. In my experiences, it is not often terribly useful even for that purpose, but it can be helpful when you’re debugging.

    For actual output, the function you want is display. This outputs the actual data itself to the output port, not a formatted representation of it.


    For completeness, Racket has an additional printing function, called print. Unlike display and write, print is explicitly designed to be used for debugging. Its output can be customized by a variety of different parameters, so the output format is uses it not necessarily predictable, and it shouldn’t be used for anything other than debugging. For that purpose, though, it’s quite useful.