How does Ruby compare to Python?? How good is DESIGN of Rubycompared to Python?
Duncan Booth
me at privacy.net
Thu Feb 26 04:34:11 EST 2004
More information about the Python-list mailing list
Thu Feb 26 04:34:11 EST 2004
- Previous message (by thread): Foundations of computing languages (was: How does Ruby compare to Python?? How good is DESIGN of Rubycompared to Python?)
- Next message (by thread): How does Ruby compare to Python?? How good is DESIGN of Rubycompared to Python?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Joe Mason <joe at notcharles.ca> wrote in news:slrnc3q0j8.jm5.joe at gate.notcharles.ca: > A better example of buond vs. unbound methods is this: > > def boundFunc(callback): > print callback(5, 6) > > def unboundFunc(obj, callback): > print callback(obj, 5, 6) > > def functionCallback(a, b): > return a + b > > class Foo: > def methodCallback(self, a, b): > return a * b + self.c > def setc(self, c): > self.c = c > >>>> boundFunc(functionCallback) > 11 >>>> f = Foo() >>>> f.setc(3) >>>> boundFunc(f.methodCallback) > 33 >>>> unboundFunc(f, Foo.methodCallback) > 33 Say I modify your example so that we only have one Func which accepts either a bound or unbound (functionCallback and Foo definitions are unchanged): >>> def Func(callback, *extra_args): print callback(*(extra_args+(5,6))) >>> Func(functionCallback) 11 >>> f = Foo() >>> f.setc(3) >>> Func(f.methodCallback) 33 >>> Func(Foo.methodCallback, f) 33 >>> Python doesn't care what type of callable it is passed, so long as it somehow ends up with the right arguments to call it. Can Ruby handle this case?
- Previous message (by thread): Foundations of computing languages (was: How does Ruby compare to Python?? How good is DESIGN of Rubycompared to Python?)
- Next message (by thread): How does Ruby compare to Python?? How good is DESIGN of Rubycompared to Python?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list