An oddity in list comparison and element assignment

  • Thread starter michael.f.ellis
  • Start date
A

Alex Martelli

Terry Reedy said:
Depends what one means by 'copy'. See below for your alternate wording.

Please give me a reasonable definition of the unadorned word "copy"
which would make this statement false. (And, just to forestall one
possible attempt: no, I cannot agree that a ``deepcopy'' is a reasonable
definition of the _unadorned_ word "copy").

Perhaps you should tone down the overwrought emotionalism and take a look
in a mirror. In *your* response to Michael you made the *same*
distinction:

I did not *DRAW* any distinction (as you did with your parenthetical
note "(not *is*)", emphasis and all) -- rather, I used one of many
reasonably interchangeable ways to word a concept. ((In the Nutshell, I
always deliberately try to pick the shortest and most concise way; in my
more spontaneous writing, I strongly tend to wilder exhuberance).

So, having deeply delved into the mirror, I still fail to find any
validity in your criticism: the phrases "S*n is the same as the
concatenation of" and "S*n the concatenation of", taken as definitions
of what S*n means, are such that your emphatic distinction has no added
value whatsoever -- I stand by this assertion and fail to see in it any
emotionalism, overwrought or otherwise. Care to _defend_ your
criticism, with some _objective_ explanation of why that parenthetical
was warranted (particularly the emphasis within it)? Or would you
rather continue the personal attacks against me and the unproven
accusations of "overwrought emotionalism" in particular?


Alex
 
S

Slawomir Nowaczyk

#>
#> > Depends what one means by 'copy'. See below for your alternate wording.
#>
#> Please give me a reasonable definition of the unadorned word "copy"
#> which would make this statement false. (And, just to forestall one
#> possible attempt: no, I cannot agree that a ``deepcopy'' is a reasonable
#> definition of the _unadorned_ word "copy").

Actually, when *I* think about the word "copy", I have in mind what
happens with files... and I to me semantics of []*3 is more like
symbolic linking, not copying. While I, personally, understand the
sentence in question "The result of S*n or n*S is the concatenation of
n copies of S" correctly, I *do* see how it might be misunderstood by
others.

Not that I know how to express it better :-(

--
Best wishes,
Slawomir Nowaczyk
( (e-mail address removed) )

Don't wake me for the end of the world unless it has very good
special effects -- Roger Zelazny
 
S

Steve Holden

Yes. You stated it quite precisely. I believe l1==l2 should always
return True and l1==l3 should always be False. (unless l3 is reassigned
as l3=l1). Your idea of a separate operator for 'all elements have
numerically equal values at the moment of comparision' is a good one.
For want of a better name, it could be called DeepCopyEquality(a,b) and
would be equivalent to a byte-by-byte comparison of two distinct
regions in memory created by a deep copies of a and b.
I suspect the word you are grasping for is "isomorphic", since your
complaint appears to be that two non-isomorphic lists can compare as equal.

He then later said:
Considering the number of new programmers who get bit by automatic
coercion, I wish Dennis Ritchie had made some different choices when he
designed C. But then I doubt he ever dreamed it would become so wildly
successful.
So he designed it badly because he didn't anticipate its ubiquity? Give
me a break. Every language designer regrets some of their decisions:
it's almost a given for design of any kind, since one makes compromises
without realising that they are compromises until usage reveals them.
Being a curmudgeon purist I'd actually prefer it if Python raised a
TypeError on float vs integer comparisons.
That's taking purity just a little too far for my taste.

Looking at how this thread developed (if such an unedifying process can
be described as "development") I hope you'll phrase future posts a
little more carefully.

regards
Steve
 
A

Alex Martelli

Slawomir Nowaczyk said:
#>
#> > Depends what one means by 'copy'. See below for your alternate wording.
#>
#> Please give me a reasonable definition of the unadorned word "copy"
#> which would make this statement false. (And, just to forestall one
#> possible attempt: no, I cannot agree that a ``deepcopy'' is a reasonable
#> definition of the _unadorned_ word "copy").

Actually, when *I* think about the word "copy", I have in mind what
happens with files...

Sure! In particular, to reproduce the concept of an object containing
references to other objects, imagine that the file is a .tar, .dmg (on
MacOSX), or other kind of "container"/"archive" kind of file, and one of
the items in its contents is a symbolic link.

When you copy the archive file, both the original and the copy now
contain symbolic links to the SAME target.
and I to me semantics of []*3 is more like
symbolic linking, not copying.

??? an _assignment_ in Python can be said to be "like symbolic linking,
not copying" -- and that's a crucial part of Python's semantics, of
course. But the Sequence*N operation has nothing to do with creating
symbolic links; it may (of course) _copy_ such links, if they're present
in the sequence, just like copying a container file copies symbolic
links it may contain -- in each case one can end up with symbolic links
to the same target. The analogy between files and Python objects is of
course not exact (partly because filesystems normally distinguish
between directories, which only contain references to files, and
"ordinary" files, that don't -- the Composite Design Pattern proceeds,
often fruitfully, by abstracting away this distinction), but in as far
as it holds, it points roughly in the right direction. (GNU's cp offers
a -R switch to explicitly perform a "recursive copy", with other
switches such as -H, -L, -P to affect what happens in that case to
symlinks -- this -R is more akin to "deep copying", except that Python's
deepcopy is simpler, and always "recurses to the hilt").
While I, personally, understand the
sentence in question "The result of S*n or n*S is the concatenation of
n copies of S" correctly, I *do* see how it might be misunderstood by
others.

Not that I know how to express it better :-(

I do find it interesting that the concept of "copy" causes such trouble,
even when the analogies used (filecopying and symlinks) would tend to
point in the right direction. The "real-life" analogy of copying a list
also points in the right direction: if I have a list of the writings I
hold on my library's top shelf, when I copy the list, both the original
and the copy point to _exactly the same_ writings -- not to separate
copies of each. If I asked an employee to "please copy this list" I
would be astonished if he or she by default also copied each other
writing that is an _item_ on the list -- surely I would expect such huge
amounts of work to happen only when explicitly requested, and the
default meaning of "copy" to be therefore ``shallow'' (wherever
applicable, that is, when copying something that references other
things). It would be interesting to study the root of the confusion in
more detail (although it's unlikely, as you indicate, that such study
would yield a different definition, concise and simple enough to be used
in a concise reference work, it would still help authors of tutorials).


Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,297
Messages
2,571,536
Members
48,284
Latest member
alphabetsalphabets

Latest Threads

Top