Python complaints

choffman at dvcorp.com choffman at dvcorp.com
Wed Dec 15 13:54:04 EST 1999


In article <38576B73.59C7BA85 at udel.edu>,
  Charles Boncelet <boncelet at udel.edu> wrote:

>
> I think all functions that operate on single things should be able to
> operate on a list of things and return a list of things. (Are there
> obvious reasons why this paradigm can't work?) Consider,

Ignoring the suggestion that 'len' itself be changed, if you truly mean
the language should automatically loop over lists, then there is
certainly an obvious reason why this can't work.

def max(arg):
  # return the maximum value in arg, which should be a list or tuple

def sin(arg):
  # return the sin of arg, which must be a single number

How does the compiler distinguish between

sin(myList)  # have to unroll myList and do multiple calls
 and
max(myList)  # must pass myList in unchanged

  or, worse

if condition:
  f = max
else:
  f = sin

f(listOrNumberDependingOnTheValueOfCondition)

Your suggestion would imply that no function could ever take a list as
an argument. The language would have to be extended so the argument to
'sin' is declared as scalar, or that to 'max' must be a list. And then
what if you want to write a function that can accept either?

On the other hand, if you are simply suggesting that all the functions
in the standard modules that accept scalar arguments should have their
bodies rewritten so they also accept lists, and do an implicit loop over
the list, your idea is reasonable. It would be a lot of work, and might
break existing programs expecting to trap errors on previously bad
arguments, and the fight over which functions make sense to change (sin:
seems OK, len: definitely not) could drag on for years!

Chris



Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list