Explanation of list reference

Chris Angelico rosuav at gmail.com
Sun Feb 16 20:59:25 EST 2014


On Mon, Feb 17, 2014 at 12:43 PM, Ned Batchelder <ned at nedbatchelder.com> wrote:
> The correct statement is "all values are objects", or "all data is objects".
> When people mistakenly say "everything is an object", they are implicitly
> only thinking about data.
>
> That said, "all data is objects" is really mostly useful in contrast to
> other languages where some data is objects and some is not.

Part of the trouble is that some code is (represented by) objects. A
function is an object, ergo it's data; a module is an object (though
that's different); a class is an object; but no other block of code
is. You can't give a name to a while loop, then pick it up and use it
somewhere else.

x = while input("Guess my number: ")!="42":
        print("Wrong number, try again.")

So a while loop isn't data. But wrap it in a function and suddenly it is:

def x():
    while input("Guess my number: ")!="42":
        print("Wrong number, try again.")

y = x
func(x)
etc

So when does code become data? When it's represented by an object.
What's an object and what's not? Data is objects, non-data is not. And
we're back to being circular again. (Does this mean we're having a
circular discussion about circular definitions?)

ChrisA



More information about the Python-list mailing list