If I have a function that prints to (current-output-port), is there an easy way to run the function without it printing to the output port?
Previously, I've used /dev/null as an output target:
(with-output-to-file "/dev/null" #:exists 'append
(lambda () (displayln "hello world")))
This is easy, but platform dependent. Also I'll sometimes forget the #:exists flag.
and NUL is Windows' equivalent of /dev/null .
Scheme provides a procedure, null? to check whether a value is (a pointer to) the empty list, i.e., a null pointer. For example, (null? foo) returns #t if the value of the variable foo is the empty list, and #f otherwise.
Yes! Use open-output-nowhere from racket/port.
(parameterize ([current-output-port (open-output-nowhere)])
(displayln "hello world"))
If you want to hide error output, override current-error-port instead / also.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With