Re: why cannot assign to function call



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
.



Relevant Pages

  • Re: why one array continues to grow after repeated call
    ... It just so happens that the semantics of the = method on an Array ... But objects mutating is completely different to assignment. ... reference to some object), and store this reference in the local ... char *a; ...
    (comp.lang.ruby)
  • Re: VB-101: Passing Arrays ByVal vs ByRef
    ... changed if an array is passed by Val. ... ' new reference ... As each function creates a new array object, ... 'secondArray' and 'secondArrayCopy'. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Need help with textboxes
    ... The JavaScript 1.5 Reference already states: ... All forms and their children are stored in an array ... use dot notation or object literals. ... No. Bracket property accessors allow their argument to be any string value. ...
    (comp.lang.javascript)
  • Re: 3rd and Final Post OCX Design Question
    ... whether there would be any difference in speed hit by creating the array on ... the client and passing a reference to the array or passing the picture and ... >> What is the difference between passing a picture as IPictureDisp as ... > the reference to the object. ...
    (microsoft.public.vb.general.discussion)
  • Re: Garbage Collection Issues in long-standing services
    ... the pinned array should get unpinned or ... The receive case is done quite well, I do create a 4K buffer and reuse it ... and remove the reference to my wrapper socket class, ...
    (microsoft.public.dotnet.languages.csharp)