Alas, the *concept* of reference is common to the human mind and human
language!

This sentence is an fine example of it, as it contains references to itself
("this", "it contains") and to the concept of reference ("example of it").

Why don't you complain about the following line of code?
>>> a = [1, 1]
It shows the exact same "problem" - how can the number 1 appear twice in the
same list?
Surely you wouldn't even consider the thought that these are different
"instances" of the number 1 (although this might be true in other
programming languages);
Your concept of what a list /is/ should be ready to accept an object
appearing as multiple elements in it.

> and then what happens if i go and change list1[0] to be '3'? it changed
twice, didn't it? so the object named mlist_a actually references the object
named list1, right?
The whole point is that names are only temporary labels, immediately
replaced by the objects they (currently) stand for.

I don't say the concept of reference is avoidable. I only refuse to present
it as a special thing.
The very same intuitive connection that exists between a name and an object
called by this name, exists in other places as well, e.g., between a
container element and the object that the container contains there (in fact,
considering that global names are just __main__.__dict__.keys(), it *is* the
same connection).

R.

-----Original Message-----
From: guy keren [mailto:[EMAIL PROTECTED] 
Sent: Sunday, December 04, 2005 4:20 AM
To: RaeNye
Cc: python@linux.org.il; 'Amit Aronovitch'
Subject: RE: teaching python variables


On Sun, 4 Dec 2005, RaeNye wrote:

> Please verify that I use the same explanation for each syntactic form 
> (list constructor, __setitem__, assignment operator).
> Also, please see that I refrain from mentioning variables and references.

ok, no references, you say. now let us go directly to the 3rd example:

> Scenario 3:
> ----------------
>  >>> list1 = [1, 2]
>  >>> list2 = [3, 4]
> We create two lists, named "list1"and "list2" respectively (with the 
> obvious content: the number 1 ...)
>
>  >>> mlist_a = [list1, list2]
> We create a list built of the object named "list1" and the object 
> named "list2" (which are the same two lists created above). We call it
"mlist_a".
>
>  >>> print mlist_a
>  [[1, 2], [3, 4]]
> Obvious.
>
>  >>> mlist_a[1] = list1
> We change the thing called "mlist_a" (which happens to be the object 
> we created two sentences ago) by replacing its first element to the 
> object named "list1".
> Note that now the object named "mlist_a" contains the same object as 
> both the first and the seconds element: a list that consists of the 
> number 1 and the number 2.

ok. an object containing the same element twice. you're using the concept of
reference, without using the word reference. to me this sounds like breaking
the rules. otherwise, how can an object contain the same object twice? does
it contain two copies of this object? or perhaps it contains 2 references to
the same object?

and then what happens if i go and change list1[0] to be '3'? it changed
twice, didn't it? so the object named mlist_a actually references the object
named list1, right?

can you explain this thing without mentioning the word "reference", as well
as without using the concept "reference"?

note that i didn't even mention things like iterators, slices (which create
a new list containing references to some of the members of an existing
list), etc.

i don't see how references can be avoided (as a concept, not just by not
using the name).

--
guy

"For world domination - press 1,
 or dial 0, and please hold, for the creator." -- nob o. dy

לענות