Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #27857

Re: Identity of values in Javascript

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail
From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.javascript
Subject Re: Identity of values in Javascript
Date Sun, 24 May 2015 23:33:51 +0100
Organization A noiseless patient Spider
Lines 62
Message-ID <874mn1ehbk.fsf@bsb.me.uk> (permalink)
References <555f256b$0$12988$c3e8da3$5496439d@news.astraweb.com> <87r3q8h3yf.fsf@bsb.me.uk> <555f7d3b$0$13002$c3e8da3$5496439d@news.astraweb.com> <87d21sgpqy.fsf@bsb.me.uk> <5561f871$0$13006$c3e8da3$5496439d@news.astraweb.com>
Mime-Version 1.0
Content-Type text/plain
Injection-Info mx02.eternal-september.org; posting-host="017616aa25f81ec581c44d76d61ba2f3"; logging-data="22262"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18nuw7hhFwycxY06nzXxuTWgK1w6QNUsNg="
Cancel-Lock sha1:pnXEWwvAZK+tvKRkKB6oUF0cQmA= sha1:S5LuNtES/eBVbz6ast6dog18HwQ=
X-BSB-Auth 1.5aea6eb9cbcdc9666477.20150524233351BST.874mn1ehbk.fsf@bsb.me.uk
Xref csiph.com comp.lang.javascript:27857

Show key headers only | View raw


Steven D'Aprano <steve@pearwood.info> writes:

> On Sat, 23 May 2015 09:24 am, Ben Bacarisse wrote:
>
>> Steven D'Aprano <steve@pearwood.info> writes:
>> 
>>> On Sat, 23 May 2015 04:17 am, Ben Bacarisse wrote:
>>>
>>>> Steven D'Aprano <steve@pearwood.info> writes:
> [...]
>> Now I beg to differ.  I don't think it is enough for your purposes
>> because it can't tell about situations you are probably interested in
>> like
>> 
>>   f(42);
>>   f(g(42));
>> 
>> There is nothing whose address can be compared here.
>
> In the first case, there is the value 42; in the second case it is the value
> returned by g(42), whatever that is. Those values must exist *somewhere* in
> memory.

No, a compiler can (and many do) perform optimisations that make the 42
vanish altogether.

But that's something of a red herring.  The point is that the language
does not do what you want.  You proposed using C's & to detect copying
but in these cases you can't.

And in the cases where is can tell you something (say where a plain
variable is the argument) you can't detect the semantics because, to
take one example, argument passing may be defined by copy in and copy
out.  The overall semantics are more important than whether a value
needs to be copied somewhere.

<snip>
> Anyway, I'm not hung up over the address of values. The address is only a
> means to an end: to confirm whether or not the value in question is copied
> on being passed as an argument to a function. (And by value I mean the
> ordinary, plain English meaning of the word: 42 is the value, not some
> pointer or handle or reference to 42.)

I'm just saying the the address of a value, being meaningless in most
programming notations, is not a means to that end.  The simplest means
to that end is to see what the language specification says about
argument passing.  You'll find that C passes by value, despite the fact
that there are many cases where no use of C's & operation can verify
that.

> I expect that the answer will be that when it comes to numbers and other
> non-object values, there is no Javascript code I can write that will
> distinguish whether or not it is copied.  I could read the source to see
> what any specific implementation does, but that's about it. Am I
> close?

I think you've been sidetracked by this address-taking idea.  The
language specification is the way to tell what the semantics of argument
passing are.  That's a lot simpler than looking at an implementation.

-- 
Ben.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Identity of values in Javascript Steven D'Aprano <steve@pearwood.info> - 2015-05-22 22:47 +1000
  Re: Identity of values in Javascript Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-22 19:17 +0100
    Re: Identity of values in Javascript Steven D'Aprano <steve@pearwood.info> - 2015-05-23 05:02 +1000
      Re: Identity of values in Javascript Steven D'Aprano <steve@pearwood.info> - 2015-05-23 05:25 +1000
      Re: Identity of values in Javascript "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-22 23:51 +0200
      Re: Identity of values in Javascript Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-23 00:24 +0100
        Re: Identity of values in Javascript Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-05-23 09:35 +0200
          Re: Identity of values in Javascript Steven D'Aprano <steve@pearwood.info> - 2015-05-23 23:04 +1000
        Re: Identity of values in Javascript "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-05-23 22:27 +0200
          Re: Identity of values in Javascript Steven D'Aprano <steve@pearwood.info> - 2015-05-25 01:58 +1000
        Re: Identity of values in Javascript Steven D'Aprano <steve@pearwood.info> - 2015-05-25 02:12 +1000
          Re: Identity of values in Javascript Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-24 23:33 +0100
            Re: Identity of values in Javascript Steven D'Aprano <steve@pearwood.info> - 2015-05-25 21:47 +1000
              Re: Identity of values in Javascript Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-26 00:10 +0100
                Re: Identity of values in Javascript Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-05-26 17:34 +0200
                Re: Identity of values in Javascript Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-26 17:03 +0100
                Re: Identity of values in Javascript Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-05-26 18:31 +0200
                Re: Identity of values in Javascript Steven D'Aprano <steve@pearwood.info> - 2015-05-27 23:40 +1000
                Re: Identity of values in Javascript Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2015-05-27 23:21 -0300
                Re: Identity of values in Javascript "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2015-05-27 19:32 -0700
                Re: Identity of values in Javascript Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-05-28 22:38 +0200
                Re: Identity of values in Javascript Scott Sauyet <scott.sauyet@gmail.com> - 2015-05-26 09:06 -0700
                Re: Identity of values in Javascript Steven D'Aprano <steve@pearwood.info> - 2015-05-27 23:02 +1000
    Re: Identity of values in Javascript Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-05-23 00:02 +0200
    Re: Identity of values in Javascript Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-05-23 09:19 +0200
  Re: Identity of values in Javascript Steven D'Aprano <steve@pearwood.info> - 2015-05-23 05:20 +1000

csiph-web