4 ms·
I think this is a good explanation of some of the very real differences between Python and Ruby. The lambda issue is almost enough to get me back to Ruby after
by DanielStraight 17y ago
I think this is a good explanation of some of the very real differences between Python and Ruby. The lambda issue is almost enough to get me back to Ruby after switching to Python. I stick with Python mostly because of syntax (especially significant whitespace) and the batteries-included philosophy. I'm also in love with a Python library called pyparsing, the equivalent of which I haven't seen in any other language.
- mbrubeck 17y agoAs an aside, pyparsing is based strongly on the excellent "Parsec" library for Haskell. A number of other languages have similar parser combinator libraries. If you're looking for Ruby libraries specifically, check out: http://treetop.rubyforge.org/ http://treetop.rubyforge.org/ (Treetop uses PEGs rather than parser combinators, but like pyparsing it integrates very well with its host language.)
- DanielStraight 17y agoGood call on Parsec. Unfortunately, I haven't found Haskell nearly as practical as Python for day-to-day work. Treetop I had not heard of. It looks interesting.
- steveklabnik 17y agoThe only problem I had with Treetop when I tried to play around with it is the same problem that I tend to have with lots of Ruby libraries. No docs other than code. Treetop has docs, but they were kind of sparse last time I looked at them.
- draegtun 17y agopyparsing, the equivalent of which I haven't seen in any other language Well the "golden oldie" equivalent in the Perl world is Parse::RecDescent (http://search.cpan.org/dist/Parse-RecDescent/ http://search.cpan.org/dist/Parse-RecDescent/). A new kid on the block is Regexp::Grammars (http://search.cpan.org/dist/Regexp-Grammars/ http://search.cpan.org/dist/Regexp-Grammars/), which is heavily based on Perl 6 rules/grammar (http://en.wikipedia.org/wiki/Perl_6_rules http://en.wikipedia.org/wiki/Perl_6_rules).
- mclin 17y agoI'm not sure I get the lambda issue. If you want a > 1 line lambda why not just define a function? def a(x): def b(): print x return b Not sure what a prototypical ruby usecase would be.
- gcampbell 17y agoThe other side of the argument: why support anonymous functions, but restrict them to one line? That seems highly arbitrary.
- kevingadd 17y agoNot one line, one statement.
- fuzzyman 17y agoNope - not arbitrary, it is because of the indentation scoping rules. Try coming up with a syntax for statement based lambdas that isn't ugly as heck.
- jashkenas 17y agoFirst, links for context. Guido's take: http://www.artima.com/weblogs/viewpost.jsp?thread=147358 http://www.artima.com/weblogs/viewpost.jsp?thread=147358 Arcieri's take: http://www.unlimitednovelty.com/2009/03/indentation-sensitivity-post-mortem.html http://www.unlimitednovelty.com/2009/03/indentation-sensitiv... It's not hard if we disallow statements, and make everything into an expression that returns a value -- something that Ruby does right. The value of a block of statements is just the value of the last statement in the block. So, whether you call it a function, or a method, or a lambda, or a block, whitespace with multi-line expressions can be made to work. The commonly-cited lambda-with-multiple-prints example, in CoffeeScript: count: -> print 'one' print 'two' print 'three'
- brutimus 17y agoI don't understand the argument either.. I use multi-line lambdas with ifs and forloops all the time. f = lambda x:( x if ( x**2 > 10 or x**2 < 5 ) else x**3 )