Modifying Class Object

A

Alf P. Steinbach

* alex23:
Ad hominem.


Ad hominem.


Ad hominem.


Ad hominem.


Ad hominem.


Ad hominem.

So the real lesson you're trying to impart is to do as you say and not
as you do?

Well, I don't think any of you guys would hold out as long as I did.

I think it's Not Nice to get personal.

But there's a limit, one can't just ignore punches every day, and you're right,
the above from me was ad hominem all the way (well, except that it doesn't
concern any technical discussion, and that I'm not injecting noise but
responding to such and trying to reduce it in the future, but still).


Cheers,

- Alf
 
A

Alf P. Steinbach

* I V:
* Steven D'Aprano:
s = [1]
t = s # Binds the name t to the object bound to the name s.
t[0] = 2 # Changes the object bound to the name t print(s) #
Checks the object via the original name.

Notice that your version describes what happens according to some
implementation, below the level of the Python virtual machine.
Consider just the

assert( t is not s )

t = s

Does this change anything at all in the computer's memory?

If it doesn't, then it has no effect whatsoever.

But since it does have an effect, a memory change has been effected.

I don't think your disagreeing with Steven here - by talking about "the
computers memory," it's clear that you are talking about the details of
an implementation of python, not the semantics of python itself. Unless,
of course, you are under the misapprehension that "the computer's memory"
is relevant to the python language, rather than the particular
implementation. Python itself has nothing to do with "computers" or
"memory"; these are mere implementation details.

You know, the programming language that doesn't need computers: Python.

:)



Cheers,

- Alf (not sure how to read your posting, but it's funny anyhow)
 
S

Steve Holden

Alf said:
* Steve Holden: [...]
In this particular part of the thread I am attempting, unsuccessfully,
to convince you that a change in *your* behavior would lead to less
hostility directed towards the way you present your ideas.

You apparently feel it is quite acceptable to tell people to "learn to
read",

I have not used that expression.

However I have suggest and emphasized that it might help to *read*
whatever one quotes, when the quoted material (such as one paragraph)
has not been read.

Telling someone to "learn to read" is a Steve Holden'sk way to imply
that the person is an ignoramus who hasn't bothered to learn to read.
Telling a person to read something that's obviously not been read is
quite another matter. So, you are misrepresenting -- again -- and in
a quite revealing way, sorry.
Pardon me? You used it on December 16 in a response to Mensanator in
message <[email protected]>

M :> How about devoting a section on downloading the source files
M :> and compiling it on a Mac?

AS:> Learn to read.

AS:> At the top of every second page it tells you that this is an
AS:> introduction based on Windows.

I am sure you will have some glib response as to why this wasn't rude at
all. Allow me to correct you - it was, and rudeness is not welcomed on
comp.lang.python. That doesn't mean it doesn't happen (why, I have even
been known to be rude myself - we are none of us perfect, after all).

I have already given ample evidence that when I am wrong I will admit
it. You, contrariwise, maintain that you will admit when you are wrong
(I believe 40% of the time was the figure you used) but I fail to
remember any single incident when you made such an admission.
Yes, in this group, but only for personal attacks.

Such as yours.

I think I've shown extreme restraint in the face of bullying from you
and some followers, and calling the insinuations bullshit is quite mild.

I don't have "followers". Assertions I make are my own, and stand alone
without the need of support. Calling them "bullshit" is indeed quite
mild, but doesn't invalidate them. You can only do that by engaging, but
instead you hysterically shout "ad hominem" whenever anyone makes a
personal remark.
That is an untrue and extremely misleading description of what you've
been doing.
I'll let that be judged on the record. You have consistently refused to
accept, despite assertions from several individuals (presumably those
you choose to characterize as my "followers", thereby allowing you to
write them off without seriously considering what they say - at least
that is how it looks from the outside) that criticism of your behavior
is not, in fact, an ad hominem attack but an attempt to engage you in
debate and have you modify that behavior.

So, for the final time: remarks about personal characteristics only
constitute ad hominem attacks ONLY when they are made for the purpose of
invalidating other (typically, in this group, technical) arguments.

If we met in person at a conference (God help us both) and you sat in an
open space session picking your nose, would you deem it an "ad hominem
attack" if I told you to stop? It sounds like it, even though I would
tell you to stop not so that others would respect your technical
arguments any less, but because by departing from the accepted standards
of behavior you would offend others.
You're complaining about the person you're hitting saying clearly what
you did.

If some truthful words about bullying can get you straight I'm for it.

Even if it means getting down to your level (and yes, I did).
Nope, I'm not complaining at all. That's your tactic: "look, Steve is
hitting me". You are entitled to write what you like on this newsgroup,
but you have to accept that it will have consequences. I am simply
pointing out that what's sauce for the goose is sauce for the gander.

regards
Steve
 
A

Alf P. Steinbach

* Steve Holden:
Alf said:
* Steven D'Aprano: [...]
accusing them of lying for having an opinion that differs from yours,
That is untrue.
Well, that says it all really.

You seem to insinuate that I'm saying that Steven is lying, and/or that Steven
is lying.

From context and your earlier similar behavior, I presume the former only.

Anyway that's a *very* dirty insinuation.

And ...

It seems you *do not understand* the difference between an incorrect statement
and a lie.

Which is very telling, I'm sorry.

And you have yet again concentrated on a personal attack via insinuation etc.,
diversion, which also is very telling, sorry.


Cheers,

- Alf
 
A

Alf P. Steinbach

* Steve Holden:
Alf said:
* Steve Holden: [...]
In this particular part of the thread I am attempting, unsuccessfully,
to convince you that a change in *your* behavior would lead to less
hostility directed towards the way you present your ideas.

You apparently feel it is quite acceptable to tell people to "learn to
read",
I have not used that expression.

However I have suggest and emphasized that it might help to *read*
whatever one quotes, when the quoted material (such as one paragraph)
has not been read.

Telling someone to "learn to read" is a Steve Holden'sk way to imply
that the person is an ignoramus who hasn't bothered to learn to read.
Telling a person to read something that's obviously not been read is
quite another matter. So, you are misrepresenting -- again -- and in
a quite revealing way, sorry.
Pardon me? You used it on December 16 in a response to Mensanator in
message <[email protected]>

M :> How about devoting a section on downloading the source files
M :> and compiling it on a Mac?

AS:> Learn to read.

AS:> At the top of every second page it tells you that this is an
AS:> introduction based on Windows.

I am sure you will have some glib response as to why this wasn't rude at
all. Allow me to correct you - it was, and rudeness is not welcomed on
comp.lang.python. That doesn't mean it doesn't happen (why, I have even
been known to be rude myself - we are none of us perfect, after all).

I have already given ample evidence that when I am wrong I will admit
it. You, contrariwise, maintain that you will admit when you are wrong
(I believe 40% of the time was the figure you used)

No, 40% of contested cases. But that was sort of a white lie. I'm not that often
wrong, and anyway it doesn't apply to me in [comp.lang.python] so far. It only
applies to groups where only things that might be incorrect are challenged.

but I fail to
remember any single incident when you made such an admission.

Your memory seems to be very very bad, since I've stated I've been wrong also in
direct debates with you.

But one person who /does/ have severe trouble admitting that he's wrong, going
to the extreme of ad hominem attacks and using terms such as "wring" to avoid
saying it (it's quite amazing, almost unbelievable) is Steve Holden.

Anyway, I was wrong about not having used that phrase "learn to read".

I'm not sure if I ever apologized directly to Mensanator for that, and now it's
history, but what I do know I did was to follow up on that comment of his,
making changes, and to acknowledge him for that in the [ack.txt] listing.

Any reader might draw conclusions from that, e.g. what I positively did or what
I possibly forgot to do -- we're not perfect beings any of us.


[Steve Holden rambling with personal characterizations & circular logic snipped]


Cheers & hth.,

- Alf
 
T

Terry Reedy

Consider just the
assert( t is not s )
t = s

Does this change anything at all in the computer's memory?

By 'computer', do you mean 'anything that computes' (including humans)
or specifically 'electronic computer'?
But since it does have an effect, a memory change has been effected.

Agreed, in whatever 'memory' the 'computer' is using.
You describe that memory change as that t has been "bound" to the same
object as s.

I prefer to use the word 'associated': namespaces are a many-to-one
association between names and objects.
By which you mean that henceforth, until the next assignment to t, t
*refers* to the same object as s.

T and s are both associated with the same object.
That explanation in terms of "refers" is necessary.

I disagree
No beginner knows what it means that a name is "bound" to something means, until it's been
explained.

I agree, which is why I am trying to avoid 'bound', etc, in favor of
'associated'. One problem of 'bind' is that it sometimes raises the
question of which is bound to which. 'Associated' avoids that.
The explanation is necessarily in terms of "refers to".

I have given an alternative, even if you still prefer yours.
When something A refers to something B, then by definition A is a
*reference* to B.

I presume you agree that the name 'Alf P. Steinbach' refers to you. Do
you then consider it to be a 'reference' to you? In either case, the
Python definition uses 'refers to' in the same way that names refer to
people, and did even before names were used in electro-mechanical
computer programming.
>Steven D'Aprano:

About 13 years ago, I noticed that electronically executable Python was
very similar to some of the designed-for-human-reading algoritm
languages (pseudocode) that were not. I then coined the oxymoron
'executable pseudocode' for Python. I see the difference between the
descriptions as reflecting the difference between Python, the executable
algorithm language and Python, the machine programming language.

I think anyone writing books using Python should at least understand the
abstract view even if he prefers to write from the more concrete view.

Terry Jan Reedy
 
A

Alf P. Steinbach

* Terry Reedy:
By 'computer', do you mean 'anything that computes' (including humans)
or specifically 'electronic computer'?

In this context I mean the virtual machine that a Python language assumes.

Doesn't matter if it's electronic or a pen-and-pencil simulation.

Agreed, in whatever 'memory' the 'computer' is using.


I prefer to use the word 'associated': namespaces are a many-to-one
association between names and objects.


T and s are both associated with the same object.


I disagree


I agree, which is why I am trying to avoid 'bound', etc, in favor of
'associated'. One problem of 'bind' is that it sometimes raises the
question of which is bound to which. 'Associated' avoids that.


I have given an alternative, even if you still prefer yours.

"Associated" is just less precise than "refers".

"Associated" is two-way.

Anyway it's just a term, and if you define it to mean a one-way reference, then
nothing substantial is changed except more room for misunderstanding.

I presume you agree that the name 'Alf P. Steinbach' refers to you. Do
you then consider it to be a 'reference' to you?

Yes, and that's irrelevant, because you can't change a name. It's a slightly
different meaning. But a name edit field with my name in it most probably refers
to me.

In either case, the
Python definition uses 'refers to' in the same way that names refer to
people, and did even before names were used in electro-mechanical
computer programming.

That's so subtle a distinction that it appears meaningless to me.

It says "refers to" but doesn't mean "refers to"?


About 13 years ago, I noticed that electronically executable Python was
very similar to some of the designed-for-human-reading algoritm
languages (pseudocode) that were not. I then coined the oxymoron
'executable pseudocode' for Python. I see the difference between the
descriptions as reflecting the difference between Python, the executable
algorithm language and Python, the machine programming language.


I think anyone writing books using Python should at least understand the
abstract view even if he prefers to write from the more concrete view.

It seems to me that you lack an understanding of the abstract here, going into
imagined and not concretely discussed differences between "refers to" and
"refers to".

Until or if (but I think it unlikely) you can explain clearly what that
difference between "refers to" and "refers to" is, it's just wordplay.


Cheers & hth.,

- Alf
 
M

Martin P. Hellwig

<cut all>
Well at least you are well written and more subtle than Xah Lee.
Though I find him also quite amusing, I do like a good flame-war every
now and again, and in that perspective I solute you.
 
S

Steven D'Aprano

About 13 years ago, I noticed that electronically executable Python was
very similar to some of the designed-for-human-reading algoritm
languages (pseudocode) that were not. I then coined the oxymoron
'executable pseudocode' for Python.

That was yours? Nice one!
 
S

Steven D'Aprano

Yes, and that's irrelevant, because you can't change a name.

Pardon me, but you most certainly can. Even Germany, which doesn't allow
people to change their legal name for frivolous reasons, makes exceptions
and will allow people to change their name if (e.g.) they have a sex
change, or if they are burdened with a name that causes them ridicule,
and presumably for their equivalent of the witness relocation program.
And even Germany doesn't presume to tell people what name they are known
by to their friends and family.

In Python, one can't change names *in place*, because strings are
immutable. (Although I have seen a hack with ctypes which allows you to
modify string objects. It makes a nice trick, but is completely useless
because of the side-effects.) Even if you could modify the name, that
would break the namespace it was stored in. But of course you can change
names in two steps:

x = something()
y = x
del x

And lo, we have changed the name x to y.
 
A

Alf P. Steinbach

* Steven D'Aprano:
Pardon me, but you most certainly can. Even Germany, which doesn't allow
people to change their legal name for frivolous reasons, makes exceptions
and will allow people to change their name if (e.g.) they have a sex
change, or if they are burdened with a name that causes them ridicule,
and presumably for their equivalent of the witness relocation program.
And even Germany doesn't presume to tell people what name they are known
by to their friends and family.

In Python, one can't change names *in place*, because strings are
immutable. (Although I have seen a hack with ctypes which allows you to
modify string objects. It makes a nice trick, but is completely useless
because of the side-effects.) Even if you could modify the name, that
would break the namespace it was stored in. But of course you can change
names in two steps:

x = something()
y = x
del x

And lo, we have changed the name x to y.

Good joke. :)


Cheers,

- Alf
 
A

Alf P. Steinbach

* Martin P. Hellwig:
<cut all>
Well at least you are well written and more subtle than Xah Lee.
Though I find him also quite amusing, I do like a good flame-war every
now and again, and in that perspective I solute you.

The technical discussion is now at point where one poster maintains that
references don't exist in Python, and another poster, in support, maintains that
"refers to" in the language spec doesn't mean "refers to" but instead means
"refers to", whatever's that meant to mean.

As a technical discussion it's meaningless drivel.

And as an argument in that technical discussion your allegation of trolling is
just yet another fallacy, and meaningless.

But in a social context, declaring support or placing oneself within a group, or
for that matter "Poisoning the well", it can make sense.

This group has an extraordinary high level of flaming and personal attacks, and
it's the only group I've seen where there are threads (I think I've seen 3,
within the last two months, not participating in them) with the regulars
reitererating how "friendly" the group is, how difficult it is to get flamed
here. In other groups it's not necessary for the regulars to point out how
friendly the group is. But then, in other groups personal attacks are rare.

And so when you mention Xah Lee I'm now wondering what is cause, and what is effect.

I was informed that he'd done extensive cross-posting, and his own web site
seems to confirm that his ISP at one time reacted to a complaint about such
cross-posting. I've also seen directly that he has employed pretty foul language
in characterizing Python in an article, and even without that language negative
loaded characterizations without any evidence to back them up (like, for
example, yours above) must be considered intentional flame bait. But did it
start that way for Xah Lee?

I'm not going to check the archives. It's enough, wrt. the point I'm making
about some regulars of the group, that even with such evidence of active
trolling at hand -- ISP reaction to cross-posting, needless foul language,
unsubstantiated characterizations -- based on my experience here I think it's
just as likely that it started out by Xah Lee being flamed, perhaps repeatedly,
with personal attacks and by group action. Or perhaps it didn't, but at this
point it would not surprise me in the slightest.


Cheers & hth.,

- Alf
 
B

Bruno Desthuilliers

Alf P. Steinbach a écrit :
(snip)
This group has an extraordinary high level of flaming and personal
attacks

Oh my...

(snip remaining non-sense)

Mr Steinbach, I bet you'll count this as another "flaming" and "personal
attack", but nonetheless : you might have happier time if you were able
to understand the distinction between disagreement and "personal attack".

(now back to more interesting readings)
 
M

Michael Sparks

Hi Alf,


Before I start, note we're talking about semantics, not
implementation. That distinction is very important.


[ of pointer ]
Yes.


For example, as I used as reference in my first posting, the Java language spec.
But it has nothing specifically to do with Java. It is a basic concept in
computer science, that (most) CS students learn in their *first year*.

E.g.

<quote src="http://cslibrary.stanford.edu/106/">
A pointer stores a reference to something. Unfortunately there is no fixed term
for the thing that the pointer points to, and across different computer
languages there is a wide variety of things that pointers point to. We use the
term pointee for the thing that the pointer points to, and we stick to the basic
properties of the pointer/pointee relationship which are true in all languages.
The term "reference" means pretty much the same thing as "pointer" --
"reference" implies a more high-level discussion, while "pointer" implies the
traditional compiled language implementation of pointers as addresses. For the
basic pointer/pointee rules covered here, the terms are effectively equivalent.
</quote>

This is where you have gone wrong. You have taken a first year
undergraduate
academic generalisation and assumed that it applies to The World. In
theory,
there is no difference between practice and theory, but in practice
there is
(so the saying goes).

The World however has another place for defining terms. That place is
of highly
varying quality, but generally a better place to correct semantics of
terms.
Who knows, eventually there may be a single commonly accepted
viewpoint. (Which
would bring a whole new level of pedantry of course )-:

I am referring to Wikipedia here. (this is a vague attempt at humour,
rather
than an attempt to patronise which it may also come over as)

Let's look at the tip of the iceberg for that:

"In computer science, a pointer is a programming language data type
whose value refers directly to (or "points to") another value
stored
elsewhere in the computer memory using its address."

http://en.wikipedia.org/wiki/Pointer_(computing)

Similarly for Call by Value: (which *is* a loaded term)

In call-by-value, the argument expression is evaluated, and the
resulting value is bound to the corresponding variable in the
function (frequently by copying the value into a new memory
region).
If the function or procedure is able to assign values to its
parameters, only its local copy is assigned — that is, anything
passed into a function call is unchanged in the caller's scope
when the function returns.

http://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_value

Call by Reference: (again, loaded term):

In call-by-reference evaluation (also referred to as pass-by-
reference),
a function receives an implicit reference to the argument, rather
than
a copy of its value. This typically means that the function can
modify
the argument- something that will be seen by its caller.

http://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_reference

Call by Sharing: (far less common term)
Also known as "call by object" or "call by object-sharing" is an
evaluation strategy first named by Barbara Liskov et al. for the
language CLU in 1974[1]. It is used by languages such as Python[2],
Iota, Java (for object references)[3], Ruby, Scheme, OCaml,
AppleScript, and many other languages.

The semantics of call-by-sharing differ from call-by-reference in
that assignments to function arguments within the function aren't
visible to the caller (unlike by-reference semantics).

http://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_sharing

As you can see, there are generally accepted terms and definitions
here,
and python is accepted as falling not into the value or reference
camp,
along with some other languages.

Understanding why IMO comes back to some basic aspects of python which
I believe trip up experienced developers. This claim is based on
talking
to someone experienced in coding for a couple of decades, who has done
a
CS degree (like me), and just didn't understand why I would use
python.

I spent an couple of _days_ explaining this, along with python's
evaluation
model, and at the end we ended up where we started:

* Python is a language which is focussed on programmer performance,
not machine performance, because relative to programmer cost,
machines are cheap. Therefore you focus your language to optimise
for the programmer, not the machine.

In this case, let's drop back to the word "pointer" which I can
understand
that you like. Indeed, it took me a fair while to let go of the word
when
talking about python, but you do have to.

Why?

Well, assume this definition isn't bad:

"In computer science, a pointer is a programming language data type
whose value refers directly to (or "points to") another value
stored
elsewhere in the computer memory using its address."

OK, let's assume that we can generalise this to ignore the address
bit,
like so:

"In computer science, a pointer is a programming language data type
whose value refers directly to (or "points to") another value
stored
elsewhere in the computer memory"

That's still not valid for python - why? Let's keep trimming it back:

"A pointer is a programming language data type
whose value refers directly to another value"

Seems OK. But not valid for python. Why? Let's keep going.

"A pointer is a data type whose value"

Ah, maybe that is the reason.

Let's look at the canonical kind of way of describing what's happening
here:
.... print world
....[1, 2, 3]

This is actually alot more complicated to explain than it might
seem if someone starts thinking "what's going on underneath".
Let's take the description you'd give to a beginner first. (OK,
depends
on beginner)

Beginner description
--------------------
A list object is created and initialised containing 3 integers -1,2 &
3.
The name x is bound to this list object.

Next a function - hello - is defined which takes one argument. When
called, the name world is bound to the object passed in. The function
body then runs and the object bound to world is used by print to print
whatever str(world) returns.

The function hello is then called with the value bound to the name x.

OK, that seems pretty simple and clear. Little odd in the terminology
perhaps, but it's clear. We deal with names and objects.

The less beginner explanation
-----------------------------

3 anonymous integer objects are created with the values 1,2 and 3.

These are bound inside a sequence which when iterated over yields
the 3 integer objects.

list is then called with this sequence object (of whatever kind it
is under the hood). A list object is then created such that:
x[0] appears bound to the integer object 1
x[1] appears bound to the integer object 2
x[2] appears bound to the integer object 3

Note I do NOT say that x[0] contains a reference to object 1,
because in languages that contain references you would:
a) have access to the reference
b) have a means of dereferencing the reference
c) Have to dereference the reference in order to obtain the
value.

This is because a reference is a form of l-value and r-value. It
is a value in itself, and refers to a value. Python does not have
such a beast. (The closest you can get is a class property, but I
digress)

In python, the language, we do not have a) or b) nor have to
do c). (indeed cannot do "c")

Why do I say "appears bound" ?

Because x[0] is syntactic sugar to a function call - x.__getitem__(0)

So...

This results in a list object being created allowing access to 3
integer
objects. The name "x" is bound to this list object.
.... print world
....

This statement (not definition) creates a function object which
accepts one argument which will be and object labelled "world"
inside the scope of the function. The resulting function object
is bound to the name "hello" in the same scope as "x".

The resulting function object also has a bunch of other attributes,
which I won't go into.
[1, 2, 3]

This is quite complex if you go down this layer. hello is a
name bound to the function object we created earlier.

Python effectivelly does this:
And uses that as the method to call with the arguments provided.

Specifically, the object that x is bound to is passed as the sole
argument to the __call__ method (wrapper) that getattr(hello,
"__call__")
returned.

The object, not a reference.
The object, not a pointer.

This is because python's semantics are designed for humans not
machines.

When applying the object we humans call x to the function
object we humans call hello
.... ... print world

....inside the scope of the function object, the name world
is bound to the object that the calling scope calls x.

This may be *implemented* in one runtime using references
in one language.
It may be *implemented* in another runtime using pointers
in another.

In PyPy the implementation will be to pass the object by
sharing. (I suspect, I've not looked at PyPy's internal's
but that's what I'd expect)

Anyhow, by hook or by crook, inside hello, the name world
is now bound to our previously created list object, which
itself has made it such that we can retrieve the 3 integers
we asked it to.

The print statement evaluates str(world), which evaluates
world.__str__(), and passes the resulting string object to
the subsystem that actually spits characters out of stdout.

That's a significantly more complicated explanation, but
still does not need or use the terms pointers or references.
The object itself is passed as the argument. The fact that
an object may have many names is by the by.

Now, you may be asking yourself (indeed I'm certain you may be)
"But how is that any difference, really, from pointers and
references".

Indeed it will seem odd to hear clearly well educated people
arguing against you saying "no, they're not pointers or
references".

It seems odd, primarily because in languages where you have
pointers and references, pointers and references are in
themselves values.

Specifically, in such languages you start talking about
l-values and r-values. An r-value is a value that may be
assigned to an l-value. An l-value essentially thus denotes
storage - a destination for an r-value.

An l-values is a machine oriented concept.
A name is a human oriented concept.

Python doesn't have l-values. It has names, and r-values.
A name is just a name, and has no value. When the name is
used syntactically, the value (object) it is bound to is
used in its place.

Thus using your example "demonstrating" that references
exist in python is something you're not yourself
understanding correctly.

Rather than thinking of names as boxes which can contain
values, think of them as labels (post it notes) that can
be stuck onto values/objects. If you do this, it will
simplify your thinking.

This was your wording:
s = ["A"]
t = s # Copies the reference.
t[0] = "B" # Changes the referenced object via the reference
copy.
print( s ) # Inspects object (now changed) via original
reference.

This is mine:
s = ["A"]

A list object is created such that the string object
"A" can be retrieved from it. The label "s" is stuck
on the object.

t = s

Sticks the label "t" onto the object as well.

t[0] = "B"

Applies the __setitem__ method of the list object we've
created with the integer object 0 and string object "B".
(What this does is anyone's guess really, someone could
have changed the implementation of list before these 4
lines were executed)

print( s )

print takes the list object which s is stuck onto. It
then calls the __str__ method of the list object passed
it, gets back a string object and spits that out stdout.

Whether we chose to use the label s or t is irrelevant,
the object _itself_ is passed in. (in terms of semantics)

Again, note, we're talking about semantics, not implementation.
That distinction is very important.

Once again, you might say, "but my explanation works well
with references and pointers", and yes in terms of
implementation, those things will exist. But if you
confuse the implementation as the semantics, you run
into problems.

For example, going back to your (incorrect) explanation:
s = ["A"]
t = s # Copies the reference.
t[0] = "B" # Changes the referenced object via the reference
copy.
print( s ) # Inspects object (now changed) via original
reference.

If t or s are references or pointers, I should be able
to deal with the reference or pointer itself as a value.

After all accepted definitions of pointer boil down to:

"A pointer is a programming language data type
whose value refers directly to another value"

And similarly for references:

"Generally, a reference is a value that enables a
program to directly access the particular data item."
http://en.wikipedia.org/wiki/Reference#Computer_science

ie both pointers and references are themselves values that
enable access to the value AND are NOT in themselves the
value they point/refer to.

In python, if I do this:

def hello(world):
print world

X = [1,2,3]
hello(X)

Then "X" is best described as a name bound to the object [1,2,3]

hello(X) is best described as calling the function bound to the
name "hello" with a single argument being the object that the
name "X" is bound to.

Inside hello, "world" is a name that is bound to whatever object
gets slung inside as its first argument. Not a pointer. Not a
reference. The object.

This semantics is radically different from languages like C,
Pascal, and similar.

One final approach.

Suppose I do this:

a = (1,2,3)
b = (4,5,6)
c = (7,8,9)
d = [a, b, c]

And I claim that a, b and c are references. (as per your
explanation)

This would mean that d[2] must also be the same reference as c.
(if you take d[2] to be a reference - which it isn't)

Therefore updating d[2] must update c.

That could imply that

d[2] += (10,)

Should result in c's reference referring to the value (7,8,9,10)

And with D having the value [ (1,2,3), (4,5,6), (7,8,9,10) ]

This is perfectly logical semantics if you're dealing with
references and pointers.

However, python doesn't deal with them. It deals with objects
and names. D does indeed result with that value, but c is
left unchanged.

The reason is because python only has r-values and names, and
no l-values.

d[2] += (10,)

Results in d[2] being evaluated - that is the __getitem__
method on the object d is bound to is called with the argument 2.
This returns the tuple object (7,8,9).

The __add__ method of that tuple object is then called, with the
argument (10,)
This returns a new tuple object (7,8,9,10)

Finalled the __setitem__ method of the object d is bound
to is called with the argument 2 and the freshly minted
tuple object (7,8,9,10).

This results in c being left unchanged. This results in D
having the correct value.

If we were dealing with references and pointers it would be
perfectly acceptable for c to be modified. In python, the
label "c" cannot be tacked onto the returned value.

Crucially, a pointer can be a pointer to a pointer, and you
can have references to references (which allows you to
dereference the pointer/reference and change the pointer/
reference).

You can't do this in python names directly. (You can come
close using properties, and by messing around in globals
and locals, but that's getting quite nasty, and not really
the same semantics.)

Anyway, I hope you've not found that patronising or ad-hominem.
If you've found my explanation overly simplistic or using too
simple phrasing, please excuse that - it's a style of writing
I've picked up on a writing course once.

In summary, if you claim that there's references or pointers
here...
s = ["A"]
t = s # Copies the reference.
t[0] = "B" # Changes the referenced object via the reference
copy.
print( s ) # Inspects object (now changed) via original
reference.

.... since references and pointers are values themselves, not
the values they refer to, how can I store a reference to a
reference? That is update the value of s from a function?

Specifically, if python has pointers or references, this should
be doable:

s = 1 # Claim is that s is a reference to 1
update(s, 2) # Update the reference s to point at the value 2

How do I write the function "update" used above in pure python.
(without messing with globals(), locals(), or diving into any
other language implementation specific concepts)

After all, I can write that in any other language that has pointers &
references.

Finally, note, we're talking about semantics, not implementation.
That distinction is very important.

If this seems odd, the reason is because python's semantics are
very much more like those of a functional language when it comes
to function calls, than it is to standard imperative languages.

Python's functions are all impure however, and side effects are
common, due to objects not (all) being immutable. Your experience
here is leading you to the wrong conclusions and incorrect reasoning.

Regards,


Michael
 
A

Alf P. Steinbach

* Michael Sparks:
Hi Alf,


Before I start, note we're talking about semantics, not
implementation. That distinction is very important.

Yes.

It would seem to readers that posters here do not grasp and are unable to grasp
that distinction.

However, all those references to implementation aspects, persisting in the face
of corrections, have just, IMHO, been consistent attempts at misrepresentation.

[ of pointer ]
Yes.

For example, as I used as reference in my first posting, the Java language spec.
But it has nothing specifically to do with Java. It is a basic concept in
computer science, that (most) CS students learn in their *first year*.

E.g.

<quote src="http://cslibrary.stanford.edu/106/">
A pointer stores a reference to something. Unfortunately there is no fixed term
for the thing that the pointer points to, and across different computer
languages there is a wide variety of things that pointers point to. We use the
term pointee for the thing that the pointer points to, and we stick to the basic
properties of the pointer/pointee relationship which are true in all languages.
The term "reference" means pretty much the same thing as "pointer" --
"reference" implies a more high-level discussion, while "pointer" implies the
traditional compiled language implementation of pointers as addresses. For the
basic pointer/pointee rules covered here, the terms are effectively equivalent.
</quote>

This is where you have gone wrong. You have taken a first year
undergraduate
academic generalisation and assumed that it applies to The World.'

I'm sorry to disappoint, but no. It was a random Google hit to find a first-year
text that perhaps posters here could understand. Not insinuiting anything about
their mental prowess or lack thereof, but just something they might understand
given a repeatedly demonstrated inability to understand such basics, or even to
understand the concept of reference to a definition of a term.

Please do consider that my usage of the term "pointer" has always, in this
thread, including the first article I posted in this thread, been with explicit
reference to the Java language spec's meaning.

You may argue that those who wrote that language spec are confused about things
or whatever, but that's rather stretching it, wouldn't you say?

In theory, there is no difference between practice and theory, but in practice
there is (so the saying goes).

The World however has another place for defining terms. That place is
of highly
varying quality, but generally a better place to correct semantics of
terms.
Who knows, eventually there may be a single commonly accepted
viewpoint. (Which
would bring a whole new level of pedantry of course )-:

I am referring to Wikipedia here. (this is a vague attempt at humour,
rather
than an attempt to patronise which it may also come over as)

I understand.

You may note that that Wikipedia article refers to an article that I wrote about
pointers in C++.

So, this must be the most silly "argument by authority" ever offered.

I find that amusing and would have included a smiley except that I think that
that would incur further flames.

It's no criticism of you; I do appreciate your effort, thanks. And I reiterate
that the meaning of "pointer" I have used is the meaning in the Java language
spec. And that that's about semantics, not about implementation, and not about C
pointers or Pascal pointers or whatever else that some would rather wish it was.



[snip]

In the following that I snipped you had good discussion except for (as I could
see) a fallacy-based denial of references existing in Python. I don't think
there's any point in discussing that further, because it's evidently a religious
matter where rational arguments -- and I've tried a few -- don't reach, in
spite of the extreme triviality of the subject matter. Thanks for the effort at
non-flaming discussion, it *is* appreciated.


Cheers & hth.,

- Alf
 
A

Alf P. Steinbach

* Bruno Desthuilliers:
Alf P. Steinbach a écrit :
(snip)

Oh my...

(snip remaining non-sense)

Mr Steinbach, I bet you'll count this as another "flaming" and "personal
attack", but nonetheless : you might have happier time if you were able
to understand the distinction between disagreement and "personal attack".

(now back to more interesting readings)

Yes, I do count this as a personal attack and flaming.

The litmus test for that is that it says something very negative about the
person you're debating with.

In addition, your statement about the earlier attacks on me, is untrue, and your
implication that it's only about attacks on me, is untrue. Both of which are
very misleading, by the way. I'm assuming that you're intentionally lying.


Cheers & hth.,

- Alf
 
S

Steve Holden

Alf said:
You may note that that Wikipedia article refers to an article that I
wrote about pointers in C++.
It's a broken link, referring to a non-existent server.

regards
Steve
 
A

Alf P. Steinbach

* Steve Holden:
It's a broken link, referring to a non-existent server.

Yes, sorry.

It's been that way a long time, and for the same reason my C++ tutorial, the
only one linked to from the C++ FAQ, is also off-line.

However, if you're interested then copies of the "pointers" doc are likely to be
floating around (at one time some mention of it somewhere generated very high
traffic over a few weeks, people downloading the PDF, and then I almost reversed
my decision not to have ads...).


Cheers & hth.,

- Alf
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top