gabriele renzi wrote: > Jeff Wood ha scritto: > > I'm not saying there are NO features of python that are cool... I like > > their list comprehensions > > > > but, I do dislike the whitespace formatting extremely. > > not that this is important, but I was'nt suggesting indentation based > syntax, which I dislike for reasons (i.e. commenting may mess syntax) > that do not apply to implict terminators. > > Anyway, I'm not really advocating this, see the 3rd word in the subject ;) > > > > <snip> > > > [ item*2 for item in items ] > > > > which is the same as: items.collect { |item| item*2 } > > > > I think their version is more readable... > > > > but beyond that, they have a cool conditional clause for the comprehensions.. > > > > [ item*2 for item in items if item > 2 ] > > > items.cool_method_name {|item| item*2 if item > 2} > > is quite doable in ruby, just collect when yielding gives you a > meaningful result, there are quite a bit of solutions. > cool_method_name is often suggested as compact_map, map_filter, > select_map and others, try googling for them. > > BTW, python's generator expressions are much cooler ;) With literal lambda's and an extension to #[] Ruby can easily do: a = [1,2,3,4,5,6] a[ { |i| i > 2 } ] #=> [3,4,5,6] In the new notation BTW: a[ -> i { i > 2 } ] Facets already has this extension, but currently one must write: a[ lambda { |i| i > 2 } ] T.