guy keren wrote:

>On Fri, 2 Dec 2005, Amit Aronovitch wrote:
>
>  
>
>>Meta
>>====
>>In this essay I'll try to clearly state some of my ideas about variables in
>>python and how to teach the subject to students new to programming.
>>    
>>
>
>lets cut the long talks. in order for me to understand what you're trying
>to do, i would like you to explain the following scenarios using the
>terms you're suggesting:
>
>  
>
Now, after I spent the long time writing this "long talks", at least
people can understand ME without endless Q&A's.
Now they can make themselves clear by saying just where their opinion
differs than mine. For people whose views are close to mine - this
allows expressing alot more with "short talks" :-)

>Scenario 1:
>   >>> list1 = [2, 3]
>   >>> list1[0] = 1
>   >>> print list1
>   [1, 3]
>
>  
>
Ahh lists...

 The first thing I have to say here is that IMHO, any real problems here
(if at all) are related to the *list* concept, which is completely
seperate from the *variable* concept. When you say a=3 you get variable
which is not a list, and when you say a=[1,2]+[3] you get two nameless
lists (not tied to any variable).

 Now the *list* concept, I have to admit, is abit more abstract. Maybe
5-years-old child one, rather than 2.5 year-old one (I'll probably know
better when my son grows up a bit ;-) ).

 I think a good daily object to compare to is a physical list written on
a piece of paper with a pencil.
 When you say list1[0] = 1, this means you go to the piece of paper,
erase the first item, and write 1 instead.

 For example: suppose you have too such notes, "the blue note" and "the
red note"

the blue note says:
 0) My dad's car
 1) 7
 2) Teddy the bear

the red note says:
 0) The blue note
 1) My dad's car
 2) The blue note

 Now, if I go and paint my car white, both blue_note[0].color (the color
of the first item in the blue note) and red_note[1].color will be white.
 If i change blue_note[1] with 5, both (red_note[0])[1] and
(red_note[2])[1] will be 5.

 The abstraction needed here is really the generalizing the "reference"
property of names to other things (you don't actually have to *say*
reference, but it might help) - you just have to understand that the
text strings on your note represent real objects the same way as names do.
 (This is not really the hard part of the concept. Maybe the harder
thing is to understand that list[0] can be a label without there being
any real text line saying "My dad's car":
  for example, the pupil might expect "list[0]" to print "'dads_car'"
instead of "repr(dads_car)" )

>Scenario 2:
>   >>> a = 1; b = 2; c = 3
>   >>> list1 = [a, b, c]
>   >>> list2 = [b, c]
>   >>> print list1
>   [1, 2, 3]
>   >>> print list2
>   [2, 3]
>
>Scenario 3:
>   >>> list1 = [1, 2]
>   >>> list2 = [3, 4]
>   >>> mlist_a = [list1, list2]
>   >>> print mlist_a
>   [[1, 2], [3, 4]]
>   >>> mlist_a[1] = list1
>   >>> print mlist_a
>   [[1, 2], [1, 2]]
>
>
>  
>
 These all seem obvious to me if you use the physical note example. If
you think otherwise, please say exactly where you think the student
would expect any other result, and we can come up with a solution.

לענות