4 ms·
In multiple languages (perl, haskell), I find myself writing a function that runs a system command and returns False (or sometimes, throws an exception) if it f
by joeyh 15y ago
In multiple languages (perl, haskell), I find myself writing a function that runs a system command and returns False (or sometimes, throws an exception) if it failed nonzero.
Also, in haskell I use these frequently to have monadic versions of some common flow control functions (some nonstandard libraries have similar functions to these but it's easier to write my own):
whenM c a = c >>= flip when a
unlessM c a = c >>= flip unless a
(>>?) = whenM
(>>!) = unlessM
-- low fixity allows eg, foo bar >>! error $ "failed " ++ meep
infixr 0 >>?
infixr 0 >>!
- jrockway 15y agoThe perl core has a way of detecting non-zero exit statuses: $ perl -Mautodie=system -e 'system("/bin/false")' "/bin/false" unexpectedly returned exit value 1 at (eval 5) line 13 at -e line 1 Pretty nice.