references/addrresses in imperative languages
Jeremy Jones
zanesdad at bellsouth.net
Sun Jun 19 23:14:32 EDT 2005
I think the only reason I read your posts is for comedy, seeing if this
is yet another "Xah Lee just threw a tantrum" post. I don't know why
I'm wasting my time responding, though... It's against my better
judgment and my previous advice to the group.
Xah Lee wrote:
>in coding Python yesterday, i was quite stung by the fact that lists
>appened to another list goes by as some so-called "reference". e.g.
>
>
What would you have it do? A list is just a collection of objects. If
I want to append my object to some list, I don't want a copy of it
appended. If I did, I'd pass in a copy of it. Otherwise, a reference
gets appended.
>t=range(5)
>n=range(3)
>n[0]='m'
>t.append(n)
>n[0]='h'
>t.append(n)
>print t
>
>
>in the following code, after some 1 hour,finally i found the solution
>of h[:]. (and that's cheating thru a google search)
>
>def parti(l,j):
> '''parti(l,j) returns l partitioned with j elements per group. If j
>is not a factor of length of l, then the reminder elements are dropped.
> Example: parti([1,2,3,4,5,6],2) returns [[1,2],[3,4],[5,6]]
> Example: parti([1,2,3,4,5,6,7],3) returns [[1,2,3],[4,5,6]]'''
> n=len(l)/j
> r=[] # result list
> h=range(j) # temp holder for sublist
> for n1 in range(n):
> for j1 in range(j):
> h[j1]=l[n1*j+j1]
> r.append( h[:] )
> return r
>
>interesting that a dictionary has copy method, but not list. (the pain
>is coupled with the uselessness of the Python doc)
>
>
You keep blasting the Python documentation. You have *yet* to produce
anything of 1/10th the quality of any piece of the Python
documentation. Until you are able to do so, I recommend shutting your
proverbial trap. You have no grounds for raising the first criticism of
the Python documentation since you have obviously not spent a
significant amount of time reading them. In another thread from
yesterday (entitled "functions with unlimited variable arguments..."),
you asked where one could find a certain feature in the documentation
(functionality which is, in my opinion, pretty basic). You appear to
have found a reference in the tutorial by yourself and one person kindly
pointed to a reference in the Python reference doc.
>------
>
>
You really don't do a good job making a good point in this section.
Maybe it's the poor English, although I can typically extract good
thought from poor English. Maybe it really is just poor thought.
>Btw, behavior such as this one, common in imperative languages and info
>tech industry, is a criminality
>
Nice. If you don't like something, just call it "a criminality". Let
me try: the criminality of Xah Lee's postings caused all occupants of
at least 4 continents to roll their eyes. You know - even though I
think my assertion had some validity, I think even there it's ridiculous
to make such a forceful assertion without a foundation for it.
> arose out of hacks C, Unix, and from
>there all associated imperative langs. (C++, csh, perl, Java... but
>each generation improves slightly)
>
>The gist of the matter is that these behaviors being the way they are
>really is because they are the easiest, most brainless implementation,
>as oppose to being a design decision.
>
>
Again, prove it. Why is passing references (or appending references -
you're not totally clear on what your beef is) brainless? What better
implementation do you have to offer the world, oh great one?
>In hindsight analysis, such language behavior forces the programer to
>fuse mathematical or algorithmic ideas with implementation details. A
>easy way to see this, is to ask yourself: how come in mathematics
>there's no such thing as "addresses/pointers/references".
>
>
Maybe because in pure mathematics there isn't the need for a computer.
Although, if we updated Descartes, Pascal, Fermat, Newton, and Leibnitz
with some of Rambaldi's works, you might see the concept of
addresses/pointers/references in pure mathematics.
>---------
>
>PS is there any difference between
>t=t+[li]
>t.append(li)
>
>
In [1]: def summit(lst, item):
...: lst = lst + item
...: print lst
...:
In [2]: def appender(lst, item):
...: lst.append(item)
...: print lst
...:
In [3]: def plus_equals(lst, item):
...: lst += item
...: print lst
...:
In [5]: import dis
In [6]: dis.dis(summit)
2 0 LOAD_FAST 0 (lst)
3 LOAD_FAST 1 (item)
6 BINARY_ADD
7 STORE_FAST 0 (lst)
3 10 LOAD_FAST 0 (lst)
13 PRINT_ITEM
14 PRINT_NEWLINE
15 LOAD_CONST 0 (None)
18 RETURN_VALUE
In [7]: dis.dis(appender)
2 0 LOAD_FAST 0 (lst)
3 LOAD_ATTR 1 (append)
6 LOAD_FAST 1 (item)
9 CALL_FUNCTION 1
12 POP_TOP
3 13 LOAD_FAST 0 (lst)
16 PRINT_ITEM
17 PRINT_NEWLINE
18 LOAD_CONST 0 (None)
21 RETURN_VALUE
In [8]: dis.dis(plus_equals)
2 0 LOAD_FAST 0 (lst)
3 LOAD_FAST 1 (item)
6 INPLACE_ADD
7 STORE_FAST 0 (lst)
3 10 LOAD_FAST 0 (lst)
13 PRINT_ITEM
14 PRINT_NEWLINE
15 LOAD_CONST 0 (None)
18 RETURN_VALUE
Figure it out.
>---------
>References:
>
>for a analysis of the same situation in Java, see
>http://xahlee.org/java-a-day/assign_array_to_list.html
>
>How to write a tutorial
>http://xahlee.org/Periodic_dosage_dir/t2/xlali_skami_cukta.html
>
> Xah
> xah at xahlee.org
>∑ http://xahlee.org/
>
>
>
It's really bad enough that you waste the time of the folks on
comp.lang.python. Why cross post like you are? I really fail to see
the point.
Jeremy Jones
More information about the Python-list
mailing list