osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tutor] beginning to code


Op 25-09-17 om 21:44 schreef Ned Batchelder:
>
> Wikipedia has the right definition of call by reference
> (https://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_reference):
>
> ?? /Call by reference/ (also referred to as /pass by reference/) is an
> ?? evaluation strategy where a function receives an implicit reference
> ?? <https://en.wikipedia.org/wiki/Reference_%28computer_science%29> to
> ?? a variable used as argument, rather than a copy of its value. This
> ?? typically means that the function can modify (i.e. assign to
> ?? <https://en.wikipedia.org/wiki/Assignment_%28computer_science%29>)
> ?? the variable used as argument?something that will be seen by its
> caller.
>
> The key idea here is that it is a reference to a *variable* that is
> passed, not a reference to a value.? Python has no references to
> variables, so it cannot support call by reference.?? Because Python
> passes references to values, it is easy to call it "call by
> reference," but that is not what the term means.
>
> The Wikipedia definition unfortunately includes "rather than a copy of
> its value," as if those are the only two options (a common
> misunderstanding).
>
> Elsewhere in this thread, someone asserted that to be call by
> reference, you have to be able to write a swap(x,y) function.? True
> call-by-reference would make this possible.? Python cannot do it.

I can write a swap function for lists in python. Can I now conclude
that lists are passed by reference?

-- 
Antoon Pardon.