5 ms·
Making this for all the different languages would be awesome. I'm thinking PHP, jquery etc. one liners.
by brador 15y ago
Making this for all the different languages would be awesome. I'm thinking PHP, jquery etc. one liners.
- wx77 15y agoDo any other languages really lend themselves to the one line command tools like perl does? 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.
- pkrumins 15y agoBenoit Hamelin did ruby one liners - http://benoithamelin.tumblr.com/ruby1line http://benoithamelin.tumblr.com/ruby1line
- jbum 15y agoAgreed - one reason why I still love Perl so much, despite its obvious warts.
- mapgrep 15y agoCompared to Ruby, one liners are more efficient in Perl because the normally infuriating cryptic variables and defaults save space. For example in Perl you can run a foreach without naming the current iteration value and it defaults to $_. $_ in turn is the default target for many commands, like print. So Perl's `print foreach @a` becomes Ruby's `a.each{|a| print a}`. Not so bad but it adds up.
- tikhonj 15y agoHere's a page for Haskell: http://www.haskell.org/haskellwiki/Blow_your_mind http://www.haskell.org/haskellwiki/Blow_your_mind 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.
- scrame 15y agoThe first example: -- 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.
- stouset 15y agoThat blows my mind, but certainly not in a good way. Ruby: $ echo 'hello world' | ruby -e 'p STDIN.read.split'
- nemetroid 15y agoBe aware that those are four separate examples made to showcase features of the language, the simplest of which being just `words`. split.hs: main = interact (show . words) $ echo hello world | runhaskell split.hs
- scrame 15y agoOK, thats not really clear from the layout. Your example is clearer, but if you have to put it in a script and pipe stuff to it, its not really a 1-liner.