mwb
2017-10-6 16:16:48

@mwb has joined the channel


mwb
2017-10-6 16:21:04

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).


mwb
2017-10-6 16:23:26

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.`


mwb
2017-10-6 16:25:49

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


leafac
2017-10-6 16:32:01

Try for-each instead of map.


mwb
2017-10-6 16:33:01

that will iterate instead of trying to create a new list?


leafac
2017-10-6 16:33:32

:+1:


mwb
2017-10-6 16:33:36

thanks!


mwb
2017-10-6 16:36:35

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)?


leafac
2017-10-6 16:47:49

Generally it’s better to avoid nesting expressions too deeply, because this makes programs harder to read 1. Also, for/* forms are preferred over map, fold and friends 2.

That said, if it’s a one-off script, then I often write these deeply nested, complicated expressions.


mwb
2017-10-6 16:57:11

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.


apg
2017-10-6 21:14:50

@mwb could also just redirect the output to /dev/null ? But, the for-each or for/* seems like the best choice.


mwb
2017-10-6 21:54:07

@apg, assume you mean running the script as $ racket my-script.rk &gt; /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.


apg
2017-10-6 21:58:42

Yes, on &gt; /dev/null sorry for not being more clear.


apg
2017-10-6 22:01:43

@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.