"always passes by reference"

Martijn Faassen m.faassen at vet.uu.nl
Sat Jul 29 11:42:14 EDT 2000


Grant Edwards <nobody at nowhere.nohow> wrote:
> In article <slrn8o3m9q.1cq.hzhu at rocket.knowledgetrack.com>, Huaiyu Zhu wrote:

>>In python there are objects and there are names.  There are operations that
>>act on existing objects and those that create new objects.  These have
>>nothing to do with mutability, except that for immutable objects, there are
>>no operations acting on existing objects.

> Looks like a good description to me.

> If you're used to thinking in C, I would describe it as

>  1) All variables are pointers.
>  
>  2) De-referencing is done automatically when you use a variable in any
>     context other than as an lvalue.
>     
>  3) All parameters are passed by value.

I think that in the context of C this is a bit confusing. If you're
passing around pointers in C, you're passing around *references*, not
values. Even though the references are obviously passed by value of the
reference. I mean, in the end the computer does need to pass around *some*
values, otherwise nothing will happen whatsoever.

This seems to be where the confusion comes in. When people claim Python
passes by value, because the *references* are being passed by value, 
that seems to be just stating that the only thing the computer can pass
in the end is numbers. If you say that, everything is by value and references
are impossible, which seems to be a useless set of semantics.

>  4) Many/most operations create a new object and return a pointer to it.

Method calls often change existing objects, so if you think of these
as operations this isn't entirely true.

>  5) Some objects can't be changed after they're created, but some objects
>     provide methods you can use to change them.

(though not all methods change objects)

> Does that make sense?    

Sure, with these caveats it makes sense.

Regards,

Martijn
-- 
History of the 20th Century: WW1, WW2, WW3?
No, WWW -- Could we be going in the right direction?



More information about the Python-list mailing list