Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #38247 > unrolled thread
| Started by | John G Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| First post | 2020-03-16 14:34 +0000 |
| Last post | 2020-03-23 18:49 -0700 |
| Articles | 20 on this page of 76 — 12 participants |
Back to article view | Back to comp.lang.javascript
Object values (continued) John G Harris <niam@jghnorth.org.uk.invalid> - 2020-03-16 14:34 +0000
Re: Object values (continued) Jon Ribbens <jon+usenet@unequivocal.eu> - 2020-03-16 14:52 +0000
Re: Object values (continued) John G Harris <niam@jghnorth.org.uk.invalid> - 2020-03-16 18:19 +0000
Re: Object values (continued) Jon Ribbens <jon+usenet@unequivocal.eu> - 2020-03-16 20:06 +0000
Re: Object values (continued) John G Harris <niam@jghnorth.org.uk.invalid> - 2020-03-17 19:01 +0000
Re: Object values (continued) Jon Ribbens <jon+usenet@unequivocal.eu> - 2020-03-17 19:55 +0000
Re: Object values (continued) John G Harris <niam@jghnorth.org.uk.invalid> - 2020-03-18 17:29 +0000
Re: Object values (continued) JJ <jj4public@vfemail.net> - 2020-03-17 12:48 +0700
Re: Object values (continued) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2020-03-17 17:51 +0100
Re: Object values (continued) John G Harris <niam@jghnorth.org.uk.invalid> - 2020-03-17 19:03 +0000
Re: Object values (continued) Andrew Poulos <ap_prog@hotmail.com> - 2020-03-18 07:20 +1100
Re: Object values (continued) John G Harris <niam@jghnorth.org.uk.invalid> - 2020-03-18 17:29 +0000
Re: Object values (continued) Andrew Poulos <ap_prog@hotmail.com> - 2020-03-19 14:21 +1100
Re: Object values (continued) John G Harris <niam@jghnorth.org.uk.invalid> - 2020-03-19 11:12 +0000
Re: Object values (continued) Andrew Poulos <ap_prog@hotmail.com> - 2020-03-20 14:33 +1100
Re: Object values (continued) John G Harris <niam@jghnorth.org.uk.invalid> - 2020-03-20 09:21 +0000
Re: Object values (continued) Andrew Poulos <ap_prog@hotmail.com> - 2020-03-21 09:56 +1100
Re: Object values (continued) John G Harris <niam@jghnorth.org.uk.invalid> - 2020-03-21 11:18 +0000
Re: Object values (continued) Andrew Poulos <ap_prog@hotmail.com> - 2020-03-22 08:45 +1100
Re: Object values (continued) John G Harris <niam@jghnorth.org.uk.invalid> - 2020-03-22 10:10 +0000
Re: Object values (continued) Andrew Poulos <ap_prog@hotmail.com> - 2020-03-23 07:44 +1100
Re: Object values (continued) John G Harris <niam@jghnorth.org.uk.invalid> - 2020-03-17 19:09 +0000
Re: Object values (continued) Richard Damon <Richard@Damon-Family.org> - 2020-03-17 16:21 -0400
Re: Object values (continued) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2020-03-17 22:57 +0100
Re: Object values (continued) Julio Di Egidio <julio@diegidio.name> - 2020-03-19 05:32 -0700
Re: Object values (continued) Silvio <silvio@internet.com> - 2020-03-19 15:26 +0100
Re: Object values (continued) John G Harris <niam@jghnorth.org.uk.invalid> - 2020-03-19 18:16 +0000
Re: Object values (continued) John G Harris <niam@jghnorth.org.uk.invalid> - 2020-03-19 18:15 +0000
Re: Object values (continued) Julio Di Egidio <julio@diegidio.name> - 2020-03-19 11:54 -0700
Re: Object values (continued) John G Harris <niam@jghnorth.org.uk.invalid> - 2020-03-20 09:11 +0000
Re: Object values (continued) John G Harris <niam@jghnorth.org.uk.invalid> - 2020-03-27 15:35 +0000
Re: Object values (continued) Julio Di Egidio <julio@diegidio.name> - 2020-03-27 09:59 -0700
Re: Object values (continued) John G Harris <niam@jghnorth.org.uk.invalid> - 2020-03-28 14:09 +0000
Re: Object values (continued) Andrew Poulos <ap_prog@hotmail.com> - 2020-03-29 14:18 +1100
Re: Object values (continued) John G Harris <niam@jghnorth.org.uk.invalid> - 2020-03-29 10:40 +0100
Re: Object values (continued) Julio Di Egidio <julio@diegidio.name> - 2020-03-29 04:41 -0700
Re: Object values (continued) John G Harris <niam@jghnorth.org.uk.invalid> - 2020-03-21 14:12 +0000
Re: Object values (continued) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2020-03-21 19:45 +0100
Re: Object values (continued) John G Harris <niam@jghnorth.org.uk.invalid> - 2020-03-22 10:30 +0000
Re: Object values (continued) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2020-03-22 23:30 +0100
Re: Object values (continued) John G Harris <niam@jghnorth.org.uk.invalid> - 2020-03-23 09:44 +0000
Re: Object values (continued) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2020-03-23 11:19 +0100
Re: Object values (continued) Julio Di Egidio <julio@diegidio.name> - 2020-03-23 05:00 -0700
Re: Object values (continued) John G Harris <niam@jghnorth.org.uk.invalid> - 2020-03-23 18:05 +0000
Re: Object values (continued) Julio Di Egidio <julio@diegidio.name> - 2020-03-23 11:50 -0700
Re: Object values (continued) John G Harris <niam@jghnorth.org.uk.invalid> - 2020-03-23 19:34 +0000
Re: Object values (continued) John G Harris <niam@jghnorth.org.uk.invalid> - 2020-03-23 18:14 +0000
Re: Object values (continued) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2020-03-23 22:21 +0100
Re: Object values (continued) John G Harris <niam@jghnorth.org.uk.invalid> - 2020-03-24 14:09 +0000
Re: Object values (continued) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2020-03-25 00:01 +0100
Re: Object values (continued) Silvio <silvio@internet.com> - 2020-03-24 01:18 +0100
Re: Object values (continued) John G Harris <niam@jghnorth.org.uk.invalid> - 2020-03-24 14:24 +0000
Re: Object values (continued) Silvio <silvio@internet.com> - 2020-03-24 15:43 +0100
Re: Object values (continued) Julio Di Egidio <julio@diegidio.name> - 2020-03-24 11:03 -0700
Re: Object values (continued) John G Harris <niam@jghnorth.org.uk.invalid> - 2020-03-24 18:23 +0000
Re: Object values (continued) Silvio <silvio@internet.com> - 2020-03-24 22:19 +0100
Re: Object values (continued) John G Harris <niam@jghnorth.org.uk.invalid> - 2020-03-25 16:34 +0000
Re: Object values (continued) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2020-03-25 23:17 +0100
Re: Object values (continued) Silvio <silvio@internet.com> - 2020-03-26 01:27 +0100
Re: Object values (continued) Andrew Poulos <ap_prog@hotmail.com> - 2020-03-26 18:58 +1100
Re: Object values (continued) Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-03-26 10:43 +0000
Re: Object values (continued) Silvio <silvio@internet.com> - 2020-03-26 12:22 +0100
Re: Object values (continued) "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2020-03-26 10:08 -0700
Re: Object values (continued) Silvio <silvio@internet.com> - 2020-03-26 18:29 +0100
Re: Object values (continued) "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2020-03-26 14:17 -0700
Re: Object values (continued) Silvio <silvio@internet.com> - 2020-03-26 23:37 +0100
Re: Object values (continued) "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2020-03-26 16:40 -0700
Re: Object values (continued) Silvio <silvio@internet.com> - 2020-03-27 11:38 +0100
Re: Object values (continued) John G Harris <niam@jghnorth.org.uk.invalid> - 2020-03-26 18:11 +0000
Re: Object values (continued) Silvio <silvio@internet.com> - 2020-03-26 19:41 +0100
Re: Object values (continued) "Mark-" <nospam@mapson.xyz> - 2020-03-25 00:00 +0000
Re: Object values (continued) John G Harris <niam@jghnorth.org.uk.invalid> - 2020-03-25 15:05 +0000
Re: Object values (continued) "Mark-" <nospam@mapson.xyz> - 2020-03-25 20:12 +0000
Re: Object values (continued) John G Harris <niam@jghnorth.org.uk.invalid> - 2020-03-26 18:09 +0000
Re: Object values (continued) John G Harris <niam@jghnorth.org.uk.invalid> - 2020-03-25 19:39 +0000
Re: Object values (continued) "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2020-03-23 18:49 -0700
Page 3 of 4 — ← Prev page 1 2 [3] 4 Next page →
| From | John G Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| Date | 2020-03-23 09:44 +0000 |
| Message-ID | <k71h7fdefbk81dqp253opti08m9uqanpot@4ax.com> |
| In reply to | #38299 |
On Sun, 22 Mar 2020 23:30:28 +0100, "Evertjan." <exxjxw.hannivoort@inter.nl.net> wrote: >John G Harris <niam@jghnorth.org.uk.invalid> wrote on 22 Mar 2020 in >comp.lang.javascript: > >> On Sat, 21 Mar 2020 19:45:00 +0100, "Evertjan." >> <exxjxw.hannivoort@inter.nl.net> wrote: <snip> >>>A primitive variable is referenced by value, >>>while an object is referenced by reference: >> >> An interesting theory > >It is not a theory, it is a fact proven by the below code. <snip> But it isn't proved. You've used a function call, f(a, b), which does the object update. Julio is saying that it is by_reference when you don't use a function; that's what I'm commenting on. John
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2020-03-23 11:19 +0100 |
| Message-ID | <XnsAB897331D3E02eejj99@194.109.6.166> |
| In reply to | #38300 |
John G Harris <niam@jghnorth.org.uk.invalid> wrote on 23 Mar 2020 in comp.lang.javascript: > But it isn't proved. You've used a function call, f(a, b), which does > the object update. It doesn't do any "object update", that's the point. > Julio is saying that it is by_reference when you > don't use a function; that's what I'm commenting on. "By reference" has only meaning in Javascript, when used in a function. -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | Julio Di Egidio <julio@diegidio.name> |
|---|---|
| Date | 2020-03-23 05:00 -0700 |
| Message-ID | <1b844369-ec19-4765-8e50-6a0ffe60c043@googlegroups.com> |
| In reply to | #38301 |
On Monday, 23 March 2020 11:19:49 UTC+1, Evertjan. wrote: > John G Harris wrote on 23 Mar 2020 > > Julio is saying that it is by_reference when you > > don't use a function; that's what I'm commenting on. > > "By reference" has only meaning in Javascript, when used in a function. I lumped together by reference as in "call by reference" (vs call by value), which is about function arguments, with "reference types" (vs value types), which is about the semantics of types, how assignment works in particular. Now can you stop these stupid and utterly ignorant polemics? Julio
[toc] | [prev] | [next] | [standalone]
| From | John G Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| Date | 2020-03-23 18:05 +0000 |
| Message-ID | <vhuh7f10acs1i8u89joljvo9hcd5iei81p@4ax.com> |
| In reply to | #38302 |
On Mon, 23 Mar 2020 05:00:40 -0700 (PDT), Julio Di Egidio <julio@diegidio.name> wrote: >On Monday, 23 March 2020 11:19:49 UTC+1, Evertjan. wrote: >> John G Harris wrote on 23 Mar 2020 > >> > Julio is saying that it is by_reference when you >> > don't use a function; that's what I'm commenting on. >> >> "By reference" has only meaning in Javascript, when used in a function. > >I lumped together by reference as in "call by reference" (vs call by value), >which is about function arguments, with "reference types" (vs value types), >which is about the semantics of types, how assignment works in particular. > >Now can you stop these stupid and utterly ignorant polemics? That's us told, Evertjan. We ignorantly didn't realise that when Julio wrote 'by reference' he meant something else. John
[toc] | [prev] | [next] | [standalone]
| From | Julio Di Egidio <julio@diegidio.name> |
|---|---|
| Date | 2020-03-23 11:50 -0700 |
| Message-ID | <1ef28d99-cc2b-473b-b13e-94af0611bb5e@googlegroups.com> |
| In reply to | #38303 |
On Monday, 23 March 2020 19:05:04 UTC+1, John G Harris wrote: > On Mon, 23 Mar 2020 05:00:40 -0700 (PDT), Julio Di Egidio > <julio@diegidio.name> wrote: > >On Monday, 23 March 2020 11:19:49 UTC+1, Evertjan. wrote: > >> John G Harris wrote on 23 Mar 2020 > > > >> > Julio is saying that it is by_reference when you > >> > don't use a function; that's what I'm commenting on. > >> > >> "By reference" has only meaning in Javascript, when used in a function. Passing arguments by reference does not exist at all in JS, you utter moron. > >I lumped together by reference as in "call by reference" (vs call by value), > >which is about function arguments, with "reference types" (vs value types), > >which is about the semantics of types, how assignment works in particular. > > > >Now can you stop these stupid and utterly ignorant polemics? > > That's us told, Evertjan. We ignorantly didn't realise that when Julio > wrote 'by reference' he meant something else. No, you are just so full of shit that you won't read English... Get the fuck out of here. *Plonk* Julio
[toc] | [prev] | [next] | [standalone]
| From | John G Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| Date | 2020-03-23 19:34 +0000 |
| Message-ID | <2o3i7fhoumf9ccss560chgl2415fo283te@4ax.com> |
| In reply to | #38305 |
On Mon, 23 Mar 2020 11:50:09 -0700 (PDT), Julio Di Egidio <julio@diegidio.name> wrote: >On Monday, 23 March 2020 19:05:04 UTC+1, John G Harris wrote: <snip> >> That's us told, Evertjan. We ignorantly didn't realise that when Julio >> wrote 'by reference' he meant something else. > >No, you are just so full of shit that you won't read English... No, the problem is that you can't remember what you wrote :- Julio wrote on 19/3/2020 : "the former is called *by value*, the latter is called *by reference*" >Get the fuck out of here. Not while you talk nonsense to the world. John
[toc] | [prev] | [next] | [standalone]
| From | John G Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| Date | 2020-03-23 18:14 +0000 |
| Message-ID | <s2vh7fprde8pf8tg4rifajl3i0uo0rp7vv@4ax.com> |
| In reply to | #38301 |
On Mon, 23 Mar 2020 11:19:26 +0100, "Evertjan." <exxjxw.hannivoort@inter.nl.net> wrote: <snip> >"By reference" has only meaning in Javascript, when used in a function. Calling something "By reference" means that the function can assign to the caller's variable. E.g It could change its value to a string. ECMAScript cannot do that. Of course, that's with the usual definition of By Reference, and I'm assuming you don't want to use eval even if that would work nowadays. John
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2020-03-23 22:21 +0100 |
| Message-ID | <XnsAB89E36F8BAFAeejj99@194.109.6.166> |
| In reply to | #38304 |
John G Harris <niam@jghnorth.org.uk.invalid> wrote on 23 Mar 2020 in comp.lang.javascript: > On Mon, 23 Mar 2020 11:19:26 +0100, "Evertjan." > <exxjxw.hannivoort@inter.nl.net> wrote: > > <snip> >>"By reference" has only meaning in Javascript, when used in a function. > > Calling something "By reference" means that the function can assign to > the caller's variable. E.g It could change its value to a string. > > ECMAScript cannot do that. > > Of course, that's with the usual definition of By Reference, and I'm > assuming you don't want to use eval even if that would work nowadays. You are totally wrong in your definition. We are talking Javascript. -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | John G Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| Date | 2020-03-24 14:09 +0000 |
| Message-ID | <es4k7f1kkstmgifuaasu816jvrkt5bios4@4ax.com> |
| In reply to | #38307 |
On Mon, 23 Mar 2020 22:21:28 +0100, "Evertjan." <exxjxw.hannivoort@inter.nl.net> wrote: >John G Harris <niam@jghnorth.org.uk.invalid> wrote on 23 Mar 2020 in >comp.lang.javascript: <snip> >> Calling something "By reference" means that the function can assign to >> the caller's variable. E.g It could change its value to a string. >> >> ECMAScript cannot do that. >> >> Of course, that's with the usual definition of By Reference, and I'm >> assuming you don't want to use eval even if that would work nowadays. > >You are totally wrong in your definition. >We are talking Javascript. Please, let us avoid using the same name for two different things. There's enough confusion already. Some languages have the feature that I described. The commonly used name for it is call_by_reference. If you look at <https://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_reference> you will see that other people have the same definition. No-one has changed that definition for nearly a year, so there's not much disagreement. What ECMAScript has is different and hasn't got a commonly used name. An accurate descriptive name would be call_by_same_value. That name works for a caller's variable holding a number, string, etc. It also works for objects : the function can change the properties of the caller's object just as much as the caller can. But you can't assign to a value, only to a variable or property. How the function knows where the object is so it can access its properties is something you don't need to know, and don't care about as long as it works. John
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2020-03-25 00:01 +0100 |
| Message-ID | <XnsAB8B4439BDDeejj99@194.109.6.166> |
| In reply to | #38311 |
John G Harris <niam@jghnorth.org.uk.invalid> wrote on 24 Mar 2020 in comp.lang.javascript: > What ECMAScript has is different Well, this is not a NG about Swahili, even when Swahili is very interesting. Habari ya jioni, -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | Silvio <silvio@internet.com> |
|---|---|
| Date | 2020-03-24 01:18 +0100 |
| Subject | Re: Object values (continued) |
| Message-ID | <5e7951cb$0$4003$e4fe514c@newszilla.xs4all.nl> |
| In reply to | #38304 |
On 3/23/20 7:14 PM, John G Harris wrote: > On Mon, 23 Mar 2020 11:19:26 +0100, "Evertjan." > <exxjxw.hannivoort@inter.nl.net> wrote: > > <snip> >> "By reference" has only meaning in Javascript, when used in a function. > > Calling something "By reference" means that the function can assign to > the caller's variable. E.g It could change its value to a string. > > ECMAScript cannot do that. > > Of course, that's with the usual definition of By Reference, and I'm > assuming you don't want to use eval even if that would work nowadays. > > John > No, you are wrong. Call by reference means the the function has access to the value of the variable that is used as the actual parameter, not the variable itself. If that value is mutable the function can change that value, effectively changing the observed value at the call site (i.e. the actual parameter variable). Doing that does NOT modify any variable used as an actual parameter, only its underlying value. C++ references, for example, are passed as pointers to the underlying value. An int& (int reference) parameter is passed as an int* (int pointer) that is automatically dereferenced (which is an operation on pointers) on both read and write access. The function can therefore overwrite the value resulting in the change of the original int value that was referred to by (not passed as) the actual parameter (including all of its aliases including any references and pointers). The only language I know that supports the semantics you describe is Algol68. There is a (subtle) observable difference between passing a REF INT and a REF REF INT. REF INT means a reference to the INT value is passed. A REF REF INT would be a reference to the reference. Calling a function with a REF REF INT formal parameter can only be done with a REF INT actual parameter (or a REF REF INT, REF REF REF INT etc) but not an INT actual parameter. Other languages like Pascal and Modula 2 support call by reference by adding the keyword VAR to the formal parameter declaration. They also do not support the semantics you describe, although they do support passing pointers by reference. Java (and with it JVM languages like Kotlin and Scala) does not support pass by reference. It passes everything by value but since the value of variables of non-primitive types are references to the object instance functions with parameters of such types are passed a copy of the reference. This allows the function to access that object value and possibly change it's state if it is mutable (which many types including String are not). Such change of state is observable at the call site. Java explicitly defines that copies of references refer to the same (as in having the same observable identity) object instance. Implicit pass by reference akin what you describe is sometimes done by Scala when it calls closures which assign to non constant variables of primitives types defined outside the closure. This is implemented by "lifting" the underlying variable to a mutable wrapper object type. An Int variable that is used in such a way will be silently compiled into a reference to a mutable object that wraps the Int value.
[toc] | [prev] | [next] | [standalone]
| From | John G Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| Date | 2020-03-24 14:24 +0000 |
| Subject | Re: Object values (continued) |
| Message-ID | <pt5k7f5bc1bvoha8unqp5fdjancqb2dleq@4ax.com> |
| In reply to | #38308 |
On Tue, 24 Mar 2020 01:18:18 +0100, Silvio <silvio@internet.com> wrote: >On 3/23/20 7:14 PM, John G Harris wrote: >> On Mon, 23 Mar 2020 11:19:26 +0100, "Evertjan." >> <exxjxw.hannivoort@inter.nl.net> wrote: >> >> <snip> >>> "By reference" has only meaning in Javascript, when used in a function. >> >> Calling something "By reference" means that the function can assign to >> the caller's variable. E.g It could change its value to a string. >> >> ECMAScript cannot do that. >> >> Of course, that's with the usual definition of By Reference, and I'm >> assuming you don't want to use eval even if that would work nowadays. >> >> John >> > >No, you are wrong. Call by reference means the the function has access >to the value of the variable that is used as the actual parameter, not >the variable itself. If that value is mutable the function can change >that value, effectively changing the observed value at the call site >(i.e. the actual parameter variable). Doing that does NOT modify any >variable used as an actual parameter, only its underlying value. The Wikipedia authors disagree with you. And so do I. >C++ references, for example, are passed as pointers to the underlying >value. <snip> Not always. Not if the caller's variable is still in scope and the compiler has turned the function call into inline code. Remember, a C++ reference is just a synonym/alias.
[toc] | [prev] | [next] | [standalone]
| From | Silvio <silvio@internet.com> |
|---|---|
| Date | 2020-03-24 15:43 +0100 |
| Subject | Re: Object values (continued) |
| Message-ID | <5e7a1c7c$0$9148$e4fe514c@newszilla.xs4all.nl> |
| In reply to | #38312 |
On 3/24/20 3:24 PM, John G Harris wrote: > On Tue, 24 Mar 2020 01:18:18 +0100, Silvio <silvio@internet.com> > wrote: > >> On 3/23/20 7:14 PM, John G Harris wrote: >>> On Mon, 23 Mar 2020 11:19:26 +0100, "Evertjan." >>> <exxjxw.hannivoort@inter.nl.net> wrote: >>> >>> <snip> >>>> "By reference" has only meaning in Javascript, when used in a function. >>> >>> Calling something "By reference" means that the function can assign to >>> the caller's variable. E.g It could change its value to a string. >>> >>> ECMAScript cannot do that. >>> >>> Of course, that's with the usual definition of By Reference, and I'm >>> assuming you don't want to use eval even if that would work nowadays. >>> >>> John >>> >> >> No, you are wrong. Call by reference means the the function has access >> to the value of the variable that is used as the actual parameter, not >> the variable itself. If that value is mutable the function can change >> that value, effectively changing the observed value at the call site >> (i.e. the actual parameter variable). Doing that does NOT modify any >> variable used as an actual parameter, only its underlying value. > > The Wikipedia authors disagree with you. And so do I. > The Wikipedia page lacks any distinction between the concept of a variable and its value. That requires the introduction of the nonsensical "Call by sharing" concept. The section with that title is complete poppycock. But if you take Wikipedia as the authoritative definition of programming concepts than we can keep this very short. > >> C++ references, for example, are passed as pointers to the underlying >> value. > <snip> > > Not always. Not if the caller's variable is still in scope and the > compiler has turned the function call into inline code. Remember, a > C++ reference is just a synonym/alias. > Inlining functions is a completely different concept since it eliminates actual call semantics and replaces it with code that has (mostly) the same observable behavior. That can indeed mean assigning to call site variables. C++ references are NOT aliases. In fact, they do not even require that the actual parameter is a variable or even an lvalue. You can call a function that expects a const int& with an int literal. In that case the compiler will stack-allocate an int with that value and pass it's address to the function.
[toc] | [prev] | [next] | [standalone]
| From | Julio Di Egidio <julio@diegidio.name> |
|---|---|
| Date | 2020-03-24 11:03 -0700 |
| Subject | Re: Object values (continued) |
| Message-ID | <b5a67723-fe52-41de-ba94-5cc2f6cfe5ae@googlegroups.com> |
| In reply to | #38313 |
On Tuesday, 24 March 2020 15:43:14 UTC+1, Silvio wrote: > On 3/24/20 3:24 PM, John G Harris wrote: > > On Tue, 24 Mar 2020 01:18:18 +0100, Silvio wrote: > > > On 3/23/20 7:14 PM, John G Harris wrote: <snip> > > The Wikipedia authors disagree with you. And so do I. > > The Wikipedia page lacks any distinction between the concept of a > variable and its value. That requires the introduction of the > nonsensical "Call by sharing" concept. The section with that title is > complete poppycock. But if you take Wikipedia as the authoritative > definition of programming concepts than we can keep this very short. Agreed, in fact I'd say at least 80% of that article is poppycock, indeed conflating semantics with implementation all over the place, still missing the specificity of lexical reduction in functional languages altogether... Julio
[toc] | [prev] | [next] | [standalone]
| From | John G Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| Date | 2020-03-24 18:23 +0000 |
| Subject | Re: Object values (continued) |
| Message-ID | <ttjk7f1qjm6i4psa227hti7aar0ffpq2hl@4ax.com> |
| In reply to | #38313 |
On Tue, 24 Mar 2020 15:43:08 +0100, Silvio <silvio@internet.com> wrote: <snip> >But if you take Wikipedia as the authoritative >definition of programming concepts than we can keep this very short. <snip> At least Wikipedia is accessible. Can you supply the name of a book, probably out of print, or refereed paper, probably costing $100 or more to buy, that says the opposite? >C++ references are NOT aliases. <snip> So you say the next two sentences are poppycock : "A reference is an alternative name for an object, an alias." "Note: a function can change the values of its non_const parameters, but these changes cannot affect the values of the arguments except where a parameter is of a reference type (8.3.2);" Can you tell which sentence was written by the inventor of C++, and which comes from the ISO standard for C++ ? In case you didn't know, in the C and C++ standards "object" means a storage area, containing anything. And if the argument in a call is an r-value then the compiler creates a temporary variable to hold it and treats it as an argument called by reference. John
[toc] | [prev] | [next] | [standalone]
| From | Silvio <silvio@internet.com> |
|---|---|
| Date | 2020-03-24 22:19 +0100 |
| Subject | Re: Object values (continued) |
| Message-ID | <5e7a796b$0$18267$e4fe514c@newszilla.xs4all.nl> |
| In reply to | #38315 |
On 3/24/20 7:23 PM, John G Harris wrote: > On Tue, 24 Mar 2020 15:43:08 +0100, Silvio <silvio@internet.com> > wrote: > > <snip> >> But if you take Wikipedia as the authoritative >> definition of programming concepts than we can keep this very short. > <snip> > > At least Wikipedia is accessible. Can you supply the name of a book, > probably out of print, or refereed paper, probably costing $100 or > more to buy, that says the opposite? > > >> C++ references are NOT aliases. > <snip> > > So you say the next two sentences are poppycock : > > "A reference is an alternative name for an object, an alias." > > "Note: a function can change the values of its non_const parameters, > but these changes cannot affect the values of the arguments except > where a parameter is of a reference type (8.3.2);" > > Can you tell which sentence was written by the inventor of C++, and > which comes from the ISO standard for C++ ? I have the printed versions of all the books Stroustrup published about C++ (starting with The C++ programming language 1st edition - 1985 and The design and evolution of C++ - 1984) which I purchased immediately when they where published here with me. I worked with a cfront-based version of C++ before these book where even published and even before the name C++ was coined (it was loosely called C with classes at the time). I wrote the first C++ compiler for the Motorola 68xxx processor family that was used in academic circles for years, even after commercial alternatives became available. No need to quote Stroustrup for me. Every variable can be considered an alias for the value it refers to. Call by reference creates more variables that refer to the same value and in that sense each reference is obviously an alias FOR THE VALUE. I took your use of the word alias as referring to the concept you talk about, of being able to modify a variable (as in: assignment to that variable) by using the variable in a call-by-reference call-site, implying the formal parameter is some kind of alias (thus: in any way connected with) the variable that was used as the actual parameter. > > In case you didn't know, in the C and C++ standards "object" means a > storage area, containing anything. And if the argument in a call is an > r-value then the compiler creates a temporary variable to hold it and > treats it as an argument called by reference. Which is exactly what I said. > > John >
[toc] | [prev] | [next] | [standalone]
| From | John G Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| Date | 2020-03-25 16:34 +0000 |
| Subject | Re: Object values (continued) |
| Message-ID | <612n7f56h629e48k0t7g0uh068aeflrmib@4ax.com> |
| In reply to | #38316 |
Anyone who believes what I said about call_by_reference can safely
ignore the rest of this article.
On Tue, 24 Mar 2020 22:19:39 +0100, Silvio <silvio@internet.com>
wrote:
<snip>
>Every variable can be considered an alias for the value it refers to.
>Call by reference creates more variables that refer to the same value
>and in that sense each reference is obviously an alias FOR THE VALUE.
>
>I took your use of the word alias as referring to the concept you talk
>about, of being able to modify a variable (as in: assignment to that
>variable) by using the variable in a call-by-reference call-site,
>implying the formal parameter is some kind of alias (thus: in any way
>connected with) the variable that was used as the actual parameter.
<snip>
Here's little C++ program, followed by a copy of what it displays on
the screen. Explain why it does what I said, or compile it and run it
yourself to see if I'm lying.
//************** Program
// JSdemo.cpp
// Program to demonstrate references
#include <iostream>
void DoSideEffect(int & v)
{
v = 127;
}
int main(int argc, char * argv[], char * /* envp */[])
{
using std::cin;
using std::cout;
using std::endl;
using std::string;
cout << endl
<< "Program to demonstrate references" << endl
<< endl
<< " J G Harris, 25.3.2020" << endl
<< endl;
// Set up
int i {19};
int & j {i};
cout << "Set up variables" << endl;
cout << "i is " << i << endl;
cout << "j is " << j << endl;
cout << endl;
// Demo local refs
j = 42; // Assign to i
cout << "Demo local references" << endl;
cout << "i is " << i << endl;
cout << "j is " << j << endl;
cout << endl;
// Demo call refs
DoSideEffect(i); // Assign to caller's i
cout << "Demo call by reference" << endl;
cout << "i is " << i << endl;
cout << "j is " << j << endl;
cout << endl;
// Hold results on screen
cout << endl
<< "To finish, press a letter, then press Enter"
<< endl;
char c;
cin >> c;
return 0;
}
//************** Output
Program to demonstrate references
J G Harris, 25.3.2020
Set up variables
i is 19
j is 19
Demo local references
i is 42
j is 42
Demo call by reference
i is 127
j is 127
To finish, press a letter, then press Enter
//************** Remark
Before you make any snarky remarks, it worked first time.
John
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2020-03-25 23:17 +0100 |
| Subject | Re: Object values (continued) |
| Message-ID | <XnsAB8BECEB14DCDeejj99@194.109.6.166> |
| In reply to | #38320 |
John G Harris <niam@jghnorth.org.uk.invalid> wrote on 25 Mar 2020 in comp.lang.javascript: > Anyone who believes what I said about call_by_reference can safely > ignore the rest of this article. Sorry, I am not religious. -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | Silvio <silvio@internet.com> |
|---|---|
| Date | 2020-03-26 01:27 +0100 |
| Subject | Re: Object values (continued) |
| Message-ID | <5e7bf70b$0$3981$e4fe514c@newszilla.xs4all.nl> |
| In reply to | #38320 |
On 3/25/20 5:34 PM, John G Harris wrote:
>
> Anyone who believes what I said about call_by_reference can safely
> ignore the rest of this article.
>
>
> On Tue, 24 Mar 2020 22:19:39 +0100, Silvio <silvio@internet.com>
> wrote:
>
> <snip>
>> Every variable can be considered an alias for the value it refers to.
>> Call by reference creates more variables that refer to the same value
>> and in that sense each reference is obviously an alias FOR THE VALUE.
>>
>> I took your use of the word alias as referring to the concept you talk
>> about, of being able to modify a variable (as in: assignment to that
>> variable) by using the variable in a call-by-reference call-site,
>> implying the formal parameter is some kind of alias (thus: in any way
>> connected with) the variable that was used as the actual parameter.
> <snip>
>
> Here's little C++ program, followed by a copy of what it displays on
> the screen. Explain why it does what I said, or compile it and run it
> yourself to see if I'm lying.
>
>
> //************** Program
>
>
> // JSdemo.cpp
> // Program to demonstrate references
>
> #include <iostream>
>
> void DoSideEffect(int & v)
> {
> v = 127;
> }
>
>
>
> int main(int argc, char * argv[], char * /* envp */[])
> {
> using std::cin;
> using std::cout;
> using std::endl;
> using std::string;
>
> cout << endl
> << "Program to demonstrate references" << endl
> << endl
> << " J G Harris, 25.3.2020" << endl
> << endl;
>
>
> // Set up
> int i {19};
> int & j {i};
>
> cout << "Set up variables" << endl;
> cout << "i is " << i << endl;
> cout << "j is " << j << endl;
> cout << endl;
>
>
> // Demo local refs
> j = 42; // Assign to i
>
> cout << "Demo local references" << endl;
> cout << "i is " << i << endl;
> cout << "j is " << j << endl;
> cout << endl;
>
>
> // Demo call refs
> DoSideEffect(i); // Assign to caller's i
>
> cout << "Demo call by reference" << endl;
> cout << "i is " << i << endl;
> cout << "j is " << j << endl;
> cout << endl;
>
>
> // Hold results on screen
> cout << endl
> << "To finish, press a letter, then press Enter"
> << endl;
> char c;
> cin >> c;
>
> return 0;
> }
>
>
> //************** Output
>
>
> Program to demonstrate references
>
> J G Harris, 25.3.2020
>
> Set up variables
> i is 19
> j is 19
>
> Demo local references
> i is 42
> j is 42
>
> Demo call by reference
> i is 127
> j is 127
>
>
> To finish, press a letter, then press Enter
>
>
> //************** Remark
>
> Before you make any snarky remarks, it worked first time.
>
> John
>
The fact that you demonstrate the exact behavior I described shows you
do not understand me.
I think the misunderstanding stems from terminology. We seem to have
different interpretations about what a variable and a value is. I use
the word variable as the mathematical notion of a symbolic name that is
at some point bound to a certain value.
In C++ variables are expressed as identifiers. These identifiers are
static (as in compile time and immutable) names for a memory location.
Depending on the kind of variable (global, local, class member) that may
may be a fixed memory address (to be resolved at load time or position
independent depending on the memory model in use), a stack frame offset
of a relative memory offset. The type associated with the identifier
determines how that memory pointed at is interpreted.
The value at the location pointed to is what I call the value associated
with the identifier (variable).
Your int& j points to the same memory location as i does, although j is
in most cases (unless optimized away by the compiler which is possible
in some cases) an actual int* that needs an extra indirection to access
the memory location associated with i. Calling a method with an int&
formal parameter is exactly the same thing. Assigning to the reference
modifies the memory at that location.
Still exactly analogous to what I have said.
But upthread you claimed that call by reference could in some cases even
lead to assigning a string to an integer variable. Even disregarding
type enforcement it would be impossible to change i into a string of any
kind. C++ will let us cast the memory associated with i to any type we
want so we can put anything we want there. We could even write some
string representation to it. But even then will any reference to i
interpret the memory at that location as an int value. Barring an
untyped language with reference type variables and C preprocessor like
macro semantics there are no programming systems in general use that
support such a thing.
Now we got onto this subject by discussing reference types (as opposed
to references like the C++ ones) and how they are passed by value in
languages like Java while still allowing modification of the referred to
objects. You brought up pass by reference, which had little or nothing
to do with reference types.
[toc] | [prev] | [next] | [standalone]
| From | Andrew Poulos <ap_prog@hotmail.com> |
|---|---|
| Date | 2020-03-26 18:58 +1100 |
| Subject | Re: Object values (continued) |
| Message-ID | <MZudnXqgqoAy_eHDnZ2dnUU7-RPNnZ2d@westnet.com.au> |
| In reply to | #38324 |
On 26/03/2020 11:27 am, Silvio wrote: > On 3/25/20 5:34 PM, John G Harris wrote: >> >> Anyone who believes what I said about call_by_reference can safely >> ignore the rest of this article. Is there anyone left that doesn't believe Harris is very busy polishing a turd? >> On Tue, 24 Mar 2020 22:19:39 +0100, Silvio <silvio@internet.com> >> wrote: >> >> <snip> >>> Every variable can be considered an alias for the value it refers to. <snip> >> //************** Program >> >> // JSdemo.cpp >> // Program to demonstrate references <snip> >> John >> > > The fact that you demonstrate the exact behaviour I described shows you > do not understand me. <good stuff snipped> Haven't you worked out by now that Harris is either trolling or polishing a turd? Andrew Poulos
[toc] | [prev] | [next] | [standalone]
Page 3 of 4 — ← Prev page 1 2 [3] 4 Next page →
Back to top | Article view | comp.lang.javascript
csiph-web