To clarify how Python handles two equal objects

avi.e.gross at gmail.com avi.e.gross at gmail.com
Fri Jan 13 22:12:37 EST 2023


Axel and others,

I can appreciate the comparison to a partially applied function but not in
this case. Not that it matters, but this example is more like creating an
object in something like machine learning and initializing parameters
without adding data. Only when you ad data and call upon some transforms and
so on, does it do something.

This case is even more general. You create an object that does NOTHING. It
simply holds a start/end/step set of up to three values. Lots of other
functions will take this object as an argument. It can be used and reused
any number of times. Strictly speaking, code like name[5:10:1] just creates
a transient slice object and then uses that to get the answer. It is not
delayed or partial as much as making one does nothing. 

Stefan mentioned functools.partial and that does create a bit of a curried
function that wraps the data and holds on to it so invoking it sort of wakes
the function up, with some or all data already accessible. A slice does not
do that and needs some other functionality to use IT alongside whatever
object you want to see a slice of.

No special behavior was intended by me. I was illustrating how some methods
of providing a selected view of an object are equally sensitive to the
underlying data changing. A partially applied function that still takes an
argument later, would have a similar problem if underlying data outside the
what is stored within the function, changed, or if the saved was a reference
to something that changed.

But this is really far from unique. In the example given of creating a
partial call, what if you made a second copy to that call then the first
variable to the partial function was re-defined. 

-----Original Message-----
From: Python-list <python-list-bounces+avi.e.gross=gmail.com at python.org> On
Behalf Of Axel Reichert
Sent: Friday, January 13, 2023 3:22 AM
To: python-list at python.org
Subject: Re: To clarify how Python handles two equal objects

<avi.e.gross at gmail.com> writes:

> As an example, you can create a named slice such as:
>
>   middle_by_two = slice(5, 10, 2)
>
> The above is not in any sense pointing at anything yet.

>From a functional programming point of view this just looks like a partially
applied function, and with this in mind the behaviour to me seems to be
completely as expected. No surprises here, or do I miss something?

Best regards

Axel
--
https://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list