osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

A question on modification of a list via a function invocation


Rustom Mody wrote:

> Models are needed
> Math is one possible model
> Machines are another

I'm not sure there's any real distinction between "math" and
"machines". A Turing machine, for example, is an idealised
mathematical model of computation.

Maybe the distiction you're trying to get at is "stateless"
vs. "stateful" models of computation? With lambda calculus
being an example of a stateless model, and a Turing machine
a stateful one.

However, I suspect that the reason you're having trouble
with the concept of "same object" in a mathematical setting
is that you're failing to consider the identity of an
object to be a piece of information in its own right that
needs to be included in the model.

If you see something like this from a Python session:

 >>> a
[1, 2]
 >>> b
[1, 2]

you *can't tell* just by looking at that whether a and
b are bound to the same object. That's an extra piece of
information that isn't shown in those textual representations.

This is why we have things like the "is" operator and
the id() function -- they provide ways of probing that
hidden information.

If you want to model Python computation purely mathematically,
you need to come up with a way to make that extra information
explicit.

There are many ways that can be done. One way is to draw
a graph. Another might be to assign id numbers to objects
and represent objects as (id, value) tuples. But the
information needs to be there in some form, otherwise
you're not modelling Python.

-- 
Greg