Re: why cannot assign to function call
- From: Steven D'Aprano <steve@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: 10 Jan 2009 23:28:09 GMT
On Sat, 10 Jan 2009 12:52:47 -0700, Joe Strout wrote:
What is the observable difference between converting an array to a
reference (pointer) to that array and passing the reference by value,
and passing the array by reference?
The difference is whether an assignment to the formal parameter (within
the function) affects the actual parameter (in the calling code). If it
does, then that's pass by reference. If it does not, then that's pass
by value.
Such a definition is incomplete. You are mischaracterising call-by-
reference as defined by a single binary state: assignment either affects
the caller, or it doesn't. If it does, it is p-b-r, if it doesn't, it's p-
b-v. According to this definition, there are no other argument passing
strategies possible. That's an enormously broad brush by which you sweep
away decades of comp sci terminology. Not just Barbara Liskov and pass-by-
object, but Algol's thunk-based pass-by-name and Haskell's pass-by-need.
In other words, you have created a false dichotomy between pass-by-
reference and pass-by-value.
There are actually three fundamental characteristics of pass-by-reference:
* passing a value by reference does not lead to the value being copied,
in contrast with pass-by-value where it does;
* modifications to the value passed by reference are visible to the
caller;
* assignments to the value passed by reference are visible to the caller.
Pascal VAR parameters have all three characteristics. Pascal non-VAR
parameters have none of them. Python parameters have two of the three. C
parameters (call-by-value) have none of them, except for arrays, where
they have all three, making arrays in C behave just like Pascal pass-by-
reference VAR parameters.
--
Steven
.
- Follow-Ups:
- Re: why cannot assign to function call
- From: Mark Wooding
- Re: why cannot assign to function call
- References:
- Re: why cannot assign to function call
- From: Derek Martin
- Re: why cannot assign to function call
- From: Steven D'Aprano
- Re: why cannot assign to function call
- From: Mark Wooding
- Re: why cannot assign to function call
- From: Aaron Brady
- Re: why cannot assign to function call
- From: Steven D'Aprano
- Re: why cannot assign to function call
- From: Mark Wooding
- Re: why cannot assign to function call
- From: Steven D'Aprano
- Re: why cannot assign to function call
- From: Mark Wooding
- Re: why cannot assign to function call
- From: Steven D'Aprano
- Re: why cannot assign to function call
- From: Aaron Brady
- Re: why cannot assign to function call
- From: Mark Wooding
- Re: why cannot assign to function call
- From: rurpy
- Re: why cannot assign to function call
- From: Mark Wooding
- Re: why cannot assign to function call
- From: rurpy
- Re: why cannot assign to function call
- From: Joe Strout
- Re: why cannot assign to function call
- Prev by Date: Re: type conversion
- Next by Date: Re: Looking for an efficient Python script to download and save a .zip file programmatically
- Previous by thread: Re: why cannot assign to function call
- Next by thread: Re: why cannot assign to function call
- Index(es):
Relevant Pages
|