why cannot assign to function call

Rhodri James rhodri at wildebst.demon.co.uk
Fri Jan 9 21:32:54 EST 2009


On Sat, 10 Jan 2009 00:21:27 -0000, <rurpy at yahoo.com> wrote:

> Joe Strout wrote:
>> rurpy at yahoo.com wrote:

[snip]

> Pointers are passed and assigned by value, just as
> other types (disputedly except arrays) are.
> One can then use that pointer to manually effect
> pass-(the-value-pointed-to)-by-reference, or sharing,
> etc.

[snip]

> In C (you have to explicitly ask for a reference
> (pointer) to something (other than arrays) if you
> want to use/pass a reference to something.
> If you simply use the name, you get by-value semantics.

>>> How would anyone develop that expectation if (from
>>> a different post in this thread), "[Python's] idea
>>> of assignment is the same as anyone else's."
>>
>> I can think of two ways:
>>
>> 1. They're new to programming in general, and would have had the same
>> expectation for any other language.  OR,
>
> IIRC, Someone posted here that his experience was
> that 12-year old kids (presumably without programming
> experience) had no problem with Python and references
> when described as "names given to an object".  (From
> memory, can't locate the post right now.)

'Twas I.  It was a rebuttal to your point that Python's assignment,
parameter passing and data model is somehow inherently more difficult
to wrap your brain around than that of other languages.  It isn't; if
anything it seems to be easier.

>> 2. They already understand some other language, and then they come here
>> and read wild claims that Python's assignment and parameter-passing
>> semantics are different from other languages.  Duped by this claim, they
>>   conclude that, if it's unlike other languages, then Python must have
>> copy semantics.
>
> I have seen no evidence of that.  If it were true I
> would expect at least some posts to refer to reading
> those "wild claims".

3. They conflate assignment, parameter passing and the data model, bring in
preconceptions of their own from other languages, and get caught out by
them.  It's quite easy to do, even within a language.  Look at the number
of times you had to say "except arrays" about C above.

> In Perl it is definitely true that you different syntax:
> @a = (1,2,3)
> @b = @a	  # Copy
> $b = \@a  # Reference

Perl has different syntax for everything.  It also has its own
peculiarities of assignment and data model that make it a less than
glowing example of comprehensibility.  List flattening, for instance,
is amazingly useful in many common Perl idioms, but really not what
you expect during assignment.

> C is the same way for everything (including pointers)
> except arrays:

Oh look, there's that exception again.

> It may be one can make a technical case that assignment
> is the same, but the reason I posted the code and results,
> was because the behavior of "=" in them produces clearly
> different results that "=" in Python.  If you want to
> then say to someone, "ignore those different results,
> '=' works exactly the same", all I can say is good luck.
> I will look forward to continuing to see weekly questions
> on this list. :-)

It would help if you were using "=" on things that were conceptually
the same across the languages, instead of things that only looked
similar.  Which is where the data model comes in, as has already been
explained at length, several times now.

-- 
Rhodri James *-* Wildebeeste Herder to the Masses



More information about the Python-list mailing list