Origin of the term "first-class object"
Rainer Deyke
rainerd at eldwood.com
Tue Nov 18 03:02:36 EST 2003
Ben Finney wrote:
> On Tue, 18 Nov 2003 03:01:35 GMT, Rainer Deyke wrote:
>> One would be passing a name as an argument
>> to a function.
>
> To accomplish what? What would you be doing with the name that you
> can't do just as easily by passing the object (by reference, as always
> happens in Python)?
Binding the name to a different object.
>> Given the immutability of certain Python objects, it is
>> often necessary to write statements in the form of
>> "x = f(x)".
>
> I don't understand the logic here. What is it that necessitates
> "x = f(x)",
For example, any "mutating" operation on x, where x is an immutable object.
Trivial and useless example:
def increment(x):
return x + 1
i = increment(i)
> and why is that undesirable?
Suppose the 'x' in 'x = f(x)' is not a simple variable, but an element in a
list
l[x * 2 + f(y)] = f(l[x * 2 + f(y)])
This statement contains an obvious redundancy that will make code
maintenance difficult. Python allows me to factor out some of the
redundancy:
index = x * 2 + f(y)
l[index] = f(l[index])
However, Python gives me no way to factor out the remaining redundancy.
--
Rainer Deyke - rainerd at eldwood.com - http://eldwood.com
More information about the Python-list
mailing list