From: Gavin Sinclair Date: 2004-04-06T07:41:57+09:00 Subject: Re: deciding between ruby and python On Tuesday, April 6, 2004, 3:07:54 AM, Vadim wrote: > On Monday 05 April 2004 11:08, Gavin Sinclair wrote: >> And there is an insurmountable limitation (I think): > .. >> chars = words = lines = 0 >> str.each do |line| >> chars += line.chomp.length >> words += line.split >> lines += 1 >> end > .. >> I don't believe [Python] can carry outside state into its >> "substitute for blocks". > Feature-by-feature comparisons are useful insofar as they help you > understand differences and similarities between the two languages > being compared. Consider English and German, for example. The former > has an "insurmountable" limitation of not having explicit case > markings for the nominative, genitive, accusative, and dative cases > the way German does. Doesn't seem insurmountable to me! :) > Now, this may be a useful thing to know, but it's useless as far as > comparing the overall expressiveness, naturalness, and ease of use of > these two languages. Very true. But a suggestion was made that Python has equivalent functionality to Ruby's blocks. Since blocks are central to the whole Ruby experience, it's worth testing that assertion. That's the context of my "insurmountable" claim above. I explicitly disclaimed any opinion about whether Python could carry out the task in general. > As Jim Weirich already pointed out in ruby-talk 96368, closures are a > poor man's objects. One way of making a function carry state in > Python is to implement it as a callable object: > $ cat poor_mans_closure.py > #!/usr/bin/python > class Foo: > "A poor man's closure" > def __init__(self, state): > self.__call__ = self._call > self.state = state > def _call(self, x, y): > return x * self.state + y Yep, and that operates at a lower level that Ruby's features, which is all I was trying to point out (and trying to do so objectively). Cheers, Gavin