Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!
like image 910
Dmitry Avatar asked Dec 11 '22 15:12

Dmitry


2 Answers

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.

like image 136
Alexis King Avatar answered Dec 25 '22 05:12

Alexis King


Use display instead of write.

like image 44
soegaard Avatar answered Dec 25 '22 04:12

soegaard