@mwb has joined the channel
hello everyone, just found this channel. I’ve been bothering the people on #general. Anyways, I was wondering if there was any way to suppress output from the racket command line. I have a script I’m running in a cron job (interpreted so it runs like $ racket script.rkt
) and the final fn is returning a list that ends up in my /var/mail/
file file. I’d prefer to suppress the output since the script is actually running a map
on that list (it is deleting a list of redis keys older than a certain time).
So I guess my options are to either suppress the output from map or the output from racket. I used “-h” on the racket executable and the only option that looked relevant was -V, --no-yield : Skip
((executable-yield-handler) <status>)’ on exitbut that strangely seems to return a greeting message:
Welcome to Racket v6.10.1.`
Here’s my final fn call in the script: >(map (lambda (number) (DEL #:rconn my-connection (bytes->string/utf–8 number))) (filter older-than-two-days (list-ref srd-stat-key-list-scan 1))) Perhaps there’s a version of map
I can use that doesn’t output — I maybe using it impurely. My intention is to take a list of redis keys, find ones that are older than two days and delete them. I tried map-filter but I just could not seem to get the syntax right
Try for-each
instead of map
.
that will iterate instead of trying to create a new list?
:+1:
thanks!
in general for racket and fp langs do you see one-liners like above (filtering and mapping across an un-named list) or multi-liners (defining a new list from the filter and then running for-each or map on the new named list)?
thanks, those seem to address my question very directly. I rarely think about performance since most scripts I write only take milliseconds to run (and run interpreted) but I write a lot of stuff in Perl and local / intermediate definitions are usually omitted in examples.
@mwb could also just redirect the output to /dev/null ? But, the for-each
or for/*
seems like the best choice.
@apg, assume you mean running the script as $ racket my-script.rk > /dev/null
and not something in Racket I will make note of that for the future, it is a good general fix. I agree that for-each
iteration seems the best solution since I do not need to do anything with the list that map
produces and it fills a gap there (thinking about the map/reduce paradigm that is so popular — map
needs to output something to be reduced) that map
isn’t really the tool I’m looking for even if it does the job. Sorry to ask another broad question but I see a lot of fp instructions that really hammer home finding other solutions than iteration. In a practical solution would you likely use recursion to write my script — which involves consuming a list and running a side-effects
laden external function on each member? I’m not interested in being dogmatic I just don’t want to write Racket code as if I were writing Perl code.
Yes, on > /dev/null
sorry for not being more clear.
@mwb side effects are a fact of life. I’d encourage you to think about how to minimize them, and contain them in small, easy to understand functions. Use pure functions when you can, and functions with side effects when you can’t.