Making this for all the different languages would be awesome. I'm thinking PHP, jquery etc. one liners.
The only one off the top of my head would be ruby but I don't have that much ruby knowledge to judge.
This kind of thing however is perl's bread and butter.
So Perl's `print foreach @a` becomes Ruby's `a.each{|a| print a}`. Not so bad but it adds up.
print a.join
Perl: print foreach @a
Ruby wins! print @a;It isn't exactly the same--some examples are two or three lines and it's more about coolness than practicality--but it's in a similar spirit, and, more importantly, also interesting.
-- split at whitespace -- "hello world" -> ["hello","world"] words
unfoldr (\b -> fmap (const . (second $ drop 1) . break (==' ') $ b) . listToMaybe $ b)
takeWhile (not . null) . evalState (repeatM $ modify (drop 1) >> State (break (== ' '))) . (' ' :)
where repeatM = sequence . repeat
fix (\f l -> if null l then [] else let (s,e) = break (==' ') l in s:f (drop 1 e))
Not really in the same spirit at all. $ echo 'hello world' | ruby -e 'p STDIN.read.split' split.hs:
main = interact (show . words)
$ echo hello world | runhaskell split.hs