| I was reading through the arc code and noticed there were several places where system was being called with strings concatenated together, the output captured, and then the trailing newline removed. So a function could be extracted that does this: (rmeol/ssystem "echo " "hi") ==> "hi"
(not sure about the names), but then I thought, "rmeol" is its own useful little piece of functionality, so it could be it's own function and "rmeol/ssystem" would combine them... and then I realized that's what : would do! (rmeol:ssystem "echo " "hi") ==> "hi"
I thought it was cool that ":" let me write the construct in the way I was thinking of it, without having to write a third function to combine the two. (Yes, I know Haskell's . does this too, but somehow my brain finds this more readable). (ssystem "echo " "hi") ==> "hi\n"
(def ssystem args
(tostring (system (apply string args))))
(rmeol "hi\n") ==> "hi"
(def rmeol (s)
(subseq s 0 (- (len s) 1)))
... and yes, of course rmeol could usefully check if the string does end in an eol character, like Perl's chomp. |