From: VK on 23 Oct 2009 21:20 .... > # Technically we are just > # replacing "ARRAY(0x365040)" > # with "foo" > $arr = "foo"; > print $arr; # foo > print "\n"; > > # Dereferencing(!) the > # reference value so telling > # to the system that we don't > # need "ARRAY(0x365040)" string, > # we need the array by that ref. > print @$alias; # 12345 IMHO that is the key part of the question. It is possible to say that JavaScript implements "automatic" (? "implied" ?) dereferencing mechanics depending on the call context, yet prevents any manual manipulations with reference values and the dereferencing process.
From: David Mark on 23 Oct 2009 23:42 On Oct 23, 8:28 pm, Jorge <jo...(a)jorgechamorro.com> wrote: > On Oct 24, 1:30 am, Lasse Reichstein Nielsen <lrn.unr...(a)gmail.com> > wrote: > > > > > Thomas 'PointedEars' Lahn <PointedE...(a)web.de> writes: > > > > Jorge wrote: > > >> Passed by reference means that you pass a reference: no > > >> more, no less. > > > "Pass by reference" isn't really a fixed meaning in computer science. > > It is likely to be taken to mean the same as "call-by-reference", > > though (by people who know what that means: passing an L-value). > > > > And it does not apply here because "reference" has a specific meaning > > > attached in general programming and so in the term "pass by reference". > > > "Reference" has many meanings. All you can really say from the word is > > that it is something that references something (different from the > > reference itself). It's also used in the ECMAScript text for something > > completely third (and at no other point in this message am I referring > > to that meaning of Reference). > > > >> More specifically, it means that what gets passed is not a copy of a > > >> certain data (whatever the type of the data), but a reference to it. > > >> It does not imply anything else, as you're pretending. > > > That's another common interpretation, matching the object passing > > semantics of JavaScript (and Java). > > I personally prefer the longer description: "Call-by-value with > > reference types". > > > > And a reference as understood in "pass by reference" is implemented as a > > > pointer to a memory location. A reference as understood in ECMAScript > > > implementations is a reference to an object (necessarily stored at a memory > > > location, but that is beside the point). > > > > As the graph showed, there can be any number of references to the same > > > object; in this case, both `bar' and the initial value of a refer to the > > > same object. If anything is copied here at all, it is the reference value. > > > Indeed. JavaScript is entirely call-by-value. However, Objects are not > > values (they are neither expressible, nor denotable). Object references > > are first class values, on the other hand. > > Aha ! > > > This matches the Java and C# terminology of "Reference types" - types > > that are not values, but where references to them are values. > > > >>> (... miss-the-point nonsense removed ...) > > > > Well, let us assume for a brief moment that you would be right, that I would > > > have missed the point, and that objects would be passed by reference in > > > ECMAScript implementations. How do you explain then that any assignment to > > > the argument named `a' does not modify the object "passed by reference" in > > > the test case? > > > Yes, it's definitly not call-by-reference. > > Yes it is -effectively- when the argument is an object: call-by- > reference === call-by-value where the value is a reference. It certainly is not (that was the point). You seem to be mixing up terms.
From: Jorge on 24 Oct 2009 06:59 On Oct 24, 5:42 am, David Mark <dmark.cins...(a)gmail.com> wrote: > On Oct 23, 8:28 pm, Jorge <jo...(a)jorgechamorro.com> wrote: > > > Yes it is -effectively- when the argument is an object: call-by- > > reference === call-by-value where the value is a reference. > > It certainly is not (that was the point). So what do you think it is that gets passed when passed by reference, if not a reference ? The behaviour is === to that of C, and it was called pass-by-reference last time I checked ~18 years ago: Everything in C is pass-by-value, even pointers. But when a pointer is passed the pointed-to data is said to be passed by reference. If it looks like a duck, swims like a duck and quacks like a duck... The nature of JS and that of C are completely different so there are certainly going to be differences for you to search and find out and point out and say hey ! do you see ? It's not exactly the same. But not in the behaviour. The behaviour is exactly identical. > You seem to be mixing up terms. May be. I'm not writing a paper on the subject, I'm speaking off the top of my head. What would be the correct terms -in your opinion- ? -- Jorge.
From: Lasse Reichstein Nielsen on 24 Oct 2009 12:55 Jorge <jorge(a)jorgechamorro.com> writes: > On Oct 24, 1:30�am, Lasse Reichstein Nielsen <lrn.unr...(a)gmail.com> > wrote: >> Yes, it's definitly not call-by-reference. > > Yes it is -effectively- when the argument is an object: call-by- > reference === call-by-value where the value is a reference. Except that's now what "call-by-reference" means. In call-by-reference you pass an L-value, which can be overwritten. I.e., you can change the binding of an *existing* variable. Passing the reference to an object allows that object to be modified, but it does not allow an existing variable to be overwritten. In C++ you can pass a reference argument, e.g.: void update(int& var) { var = 42; } int x = 0; update(x); // x is now 42. This passes the *variable* x to the function, not the value that x is bound to. You can't do that in Javascript, since all arguments in Javascript are values. Calls are call-by-value, with reference-types (which, as was also pointed out, has been called call-by-sharing, and in some circles (but definitly not all) pass-by-reference). Wikipedia also explains why this is not call-by-reference. /L -- Lasse Reichstein Holst Nielsen 'Javascript frameworks is a disruptive technology'
From: Jorge on 24 Oct 2009 13:28
On Oct 24, 6:55 pm, Lasse Reichstein Nielsen <lrn.unr...(a)gmail.com> wrote: > Jorge <jo...(a)jorgechamorro.com> writes: > > On Oct 24, 1:30 am, Lasse Reichstein Nielsen <lrn.unr...(a)gmail.com> > > wrote: > >> Yes, it's definitly not call-by-reference. > > > Yes it is -effectively- when the argument is an object: call-by- > > reference === call-by-value where the value is a reference. > > Except that's now what "call-by-reference" means. > In call-by-reference you pass an L-value, which can be overwritten. > I.e., you can change the binding of an *existing* variable. > > Passing the reference to an object allows that object to be modified, > but it does not allow an existing variable to be overwritten. > > In C++ you can pass a reference argument, e.g.: > > void update(int& var) { > var = 42; > } > int x = 0; > update(x); > // x is now 42. > > This passes the *variable* x to the function, not the value that x is > bound to. You can't do that in Javascript, since all arguments in > Javascript are values. Calls are call-by-value, with reference-types > (which, as was also pointed out, has been called call-by-sharing, and > in some circles (but definitly not all) pass-by-reference). Wikipedia > also explains why this is not call-by-reference. I know. Vars can't be passed by reference in JS. But that does *not* say anything about the way in which objects are passed. Now consider this by-the-book C pass-by-reference example: typedef struct { char property[333]; } anObject; anObject o; anObject *aReference= &o; void update (anObject *reference) { reference->property= "something"; } update(aReference); Which is exactly what JS does to pass an object. -- Jorge. |