Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Racket equivalent of /dev/null?

Tags:

racket

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.

like image 672
Ben Greenman Avatar asked Dec 13 '15 01:12

Ben Greenman


People also ask

What is the Windows equivalent of Dev Null?

and NUL is Windows' equivalent of /dev/null .

How do I check for an empty list in scheme?

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.


1 Answers

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.

like image 131
Ben Greenman Avatar answered Jan 04 '23 00:01

Ben Greenman