Problem with assigning variables of type List
Paul Foley
see at below.invalid
Wed Aug 21 01:30:14 EDT 2002
On Wed, 21 Aug 2002 03:46:00 GMT, Hans Nowak wrote:
>> entered? Yup, Python does that. Only the values are passed, and
>> changes to the arguments within the called procedure have no effect on
>> the actual arguments as seen by the caller? Right again. Python
>> meets that definition. I guess it's call-by-value (what a surprise!)
> Umm... changes to the arguments do seem to affect them as seen by the caller.
Changing the object affects the caller's view of the same object, of
course -- it's the same object! You can't alter the _argument_ in the
caller. I.e., calling any foo(x) can't change the identity of x.
> I guess one could argue that the "value" passed here is an object, in this case
> the list object, and the identity of that object cannot be changed by the
> function in such a way that the caller ends up with a different object. The
> id() of list a in the example is the same before and after the call.
Exactly.
> However, by that line of reasoning, C doesn't have call by reference either:
Correct; C doesn't have call by reference. (C++ does, though)
> void foo(int *a)
> {
> *a = 42;
> }
> (I hope the syntax is right, my C is a bit rusty.)
> By this reasoning, the above is obviously call by value as well. The value
> being passed is a pointer, and the function isn't capable of changing the
> pointer; it is capable of changing the integer it points to, but that's
> something different.
Right!
>> CALL-BY-REFERENCE
>>
>> An argument passing convention where the address of an argument
>> variable is passed to a function or procedure, as opposed to where
>> the value of the argument expression is passed. Execution of the
>> function or procedure may have side-effects on the actual argument
>> as seen by the caller. The C language's "&" (address of) and "*"
>> (dereference) operators allow the programmer to code explicit
>> call-by-reference.
> If you accept that C can do call by reference, then so can Python.
C doesn't do call by reference. You can manually construct pointers
to values, if you have something to point at (i.e., you can't make a
pointer to a literal, or the result of an equation or function call,
without involving a variable), but it's still call by value of the
pointer (when you pass &a for some variable a, you're not passing "the
address of the argument variable"; the argument is &a, not a. You're
passing the _value_ of &a -- which is the address of a, but that's
utterly beside the point)
--
For þæm se þe his cræft forlætt, se bið fram þæm cræfte forlæten.
-- Ælfric
(setq reply-to
(concatenate 'string "Paul Foley " "<mycroft" '(#\@) "actrix.gen.nz>"))
More information about the Python-list
mailing list