language design question
Terry Reedy
tjreedy at udel.edu
Mon Jul 10 00:20:01 EDT 2006
"OKB (not okblacke)" <brenNOSPAMbarn at NObrenSPAMbarn.net> wrote in message
news:Xns97FBA13B0B9BBOKB at 81.174.50.80...
> Terry Reedy wrote:
>
>> Consider
>>>>> map(len, ('abc', (1,2,3), [1,2], {1:2}))
>> [3, 3, 2, 1]
>>
>> Now try to rewrite this using methods (member functions).
>
> [a.len() for a in ('abc', (1,2,3), [1,2], {1:2})]
What I meant and should have said more specificly:
try rewriting the map call or any similar call of a 2nd-order function as
a call of the same function using methods. Map here stands for the class
of functions that take a function as an arg and apply it to an unknown
(until runtime) type or to a mixture of types. Its particular replacement
(not rewrite, as I meant the word) does not apply to the generic pattern.
This can be done (since 2.2) either with or without using the operater
module. Until 2.2, many builtin classes, including strings, tuples, and
number, did not have visible methods.
The underlying answer to the original question is that while Pyt;hon is
object-based, it is not strictly OO but is intentionally multiparadigmatic
and will remain so. For instance, no one will be forced to replace the
procedural expression 'a+b' with the strict OO equivalent 'a .__add__(b)'.
But anyone is free to do so in their own code, just as with ob.__len__()
for len(ob).
Terry Jan Reedy
More information about the Python-list
mailing list