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


Groups > comp.lang.javascript > #29105 > unrolled thread

Re: array-like objects

Started byJoao Rodrigues <groups_jr-1@yahoo.com.br>
First post2016-01-02 13:27 -0200
Last post2016-01-04 00:18 +0100
Articles 11 on this page of 31 — 8 participants

Back to article view | Back to comp.lang.javascript

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: array-like objects Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2016-01-02 13:27 -0200
    Re: array-like objects Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-01-02 20:48 +0100
      Re: array-like objects John Harris <niam@jghnorth.org.uk.invalid> - 2016-01-03 15:50 +0000
        Re: array-like objects Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-01-03 16:59 +0100
          Re: array-like objects John Harris <niam@jghnorth.org.uk.invalid> - 2016-01-04 11:15 +0000
            Re: array-like objects Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-01-04 15:27 +0100
              Re: array-like objects Tim Streater <timstreater@greenbee.net> - 2016-01-04 15:57 +0000
              Re: array-like objects John Harris <niam@jghnorth.org.uk.invalid> - 2016-01-05 16:47 +0000
                Re: array-like objects Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-01-05 20:13 +0100
                  Re: array-like objects John Harris <niam@jghnorth.org.uk.invalid> - 2016-01-06 16:24 +0000
                    Re: array-like objects Aleksandro <aleksandro@gmx.com> - 2016-01-06 14:45 -0300
                    Re: array-like objects Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-01-06 19:27 +0100
                      Re: array-like objects John Harris <niam@jghnorth.org.uk.invalid> - 2016-01-07 11:00 +0000
                  Re: array-like objects John Harris <niam@jghnorth.org.uk.invalid> - 2016-01-08 17:02 +0000
                    Re: array-like objects John Harris <niam@jghnorth.org.uk.invalid> - 2016-01-09 20:07 +0000
                      Re: array-like objects Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-01-10 09:03 +0100
                        Re: array-like objects John Harris <niam@jghnorth.org.uk.invalid> - 2016-01-10 10:03 +0000
                          Re: array-like objects Andrew Poulos <ap_prog@hotmail.com> - 2016-01-10 23:21 +1100
                            Re: array-like objects John Harris <niam@jghnorth.org.uk.invalid> - 2016-01-10 15:59 +0000
                      Re: array-like objects John Harris <niam@jghnorth.org.uk.invalid> - 2016-01-10 15:30 +0000
                        Re: array-like objects John Harris <niam@jghnorth.org.uk.invalid> - 2016-01-11 11:03 +0000
                          Re: array-like objects "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-01-11 10:36 -0800
                            Re: array-like objects John Harris <niam@jghnorth.org.uk.invalid> - 2016-01-12 10:59 +0000
                              Re: array-like objects "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-01-12 12:47 +0100
                    Re: array-like objects John Harris <niam@jghnorth.org.uk.invalid> - 2016-02-06 10:50 +0000
                      Re: array-like objects Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-02-09 05:01 +0100
                        Re: array-like objects John Harris <niam@jghnorth.org.uk.invalid> - 2016-02-09 19:07 +0000
                        Re: array-like objects John Harris <niam@jghnorth.org.uk.invalid> - 2016-02-09 19:23 +0000
    Re: array-like objects Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2016-01-03 04:26 -0800
      Re: array-like objects Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-01-03 16:54 +0100
        Re: array-like objects Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-01-04 00:18 +0100

Page 2 of 2 — ← Prev page 1 [2]


#29224

FromJohn Harris <niam@jghnorth.org.uk.invalid>
Date2016-01-11 11:03 +0000
Message-ID<ft279bpb66pss8jb83s4vukot1ir8712e9@4ax.com>
In reply to#29210
On 10 Jan 2016 17:22:41 GMT, ram@zedat.fu-berlin.de (Stefan Ram)
wrote:

  <snip>
>  This would be physics, not mathematics.
  <snip>
>  This is physics, not mathematics.
  <snip>

Come off it! Look up "unreasonable effectiveness of mathematics" in
Wikipedia.

Quantum theory and general relativity both use mathematics to produce
significant results. Both concern systems that change. Neither
requires 2.51 to become some other number.

  John

[toc] | [prev] | [next] | [standalone]


#29234

From"Michael Haufe (TNO)" <tno@thenewobjective.com>
Date2016-01-11 10:36 -0800
Message-ID<0bc06a76-694c-496f-adaf-bad3ea7d616c@googlegroups.com>
In reply to#29224
John Harris wrote:

> Come off it! Look up "unreasonable effectiveness of mathematics" in Wikipedia.

What does this debatable claim have to do with anything?

[toc] | [prev] | [next] | [standalone]


#29237

FromJohn Harris <niam@jghnorth.org.uk.invalid>
Date2016-01-12 10:59 +0000
Message-ID<m4n99b1og9sg60sp3rakouoka6sot6qj4r@4ax.com>
In reply to#29234
On Mon, 11 Jan 2016 10:36:15 -0800 (PST), "Michael Haufe (TNO)"
<tno@thenewobjective.com> wrote:

>John Harris wrote:
>
>> Come off it! Look up "unreasonable effectiveness of mathematics" in Wikipedia.
>
>What does this debatable claim have to do with anything?

It's technical, but On Topic. Stefan objects to mathematics being used
to describe the real world, ECMAScript in particular. I don't think
we'll ever agree about this.

  John

[toc] | [prev] | [next] | [standalone]


#29238

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2016-01-12 12:47 +0100
Message-ID<XnsA58D821CBE41Deejj99@194.109.6.166>
In reply to#29237
John Harris wrote on 12 Jan 2016 in comp.lang.javascript:

> It's technical, but On Topic. Stefan objects to mathematics being used
> to describe the real world, ECMAScript in particular. I don't think
> we'll ever agree about this.

To some, ECMAScript is the real world.

Perhaps we and the world are all in an elaborate computer programme,
written in ECMAScript.

That would make this NG the only NG with at least some reality.

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#29559

FromJohn Harris <niam@jghnorth.org.uk.invalid>
Date2016-02-06 10:50 +0000
Message-ID<gtjbbb1hvr67c0o2gmmhkkql2gep5novad@4ax.com>
In reply to#29178
On Fri, 08 Jan 2016 17:02:52 +0000, John Harris
<niam@jghnorth.org.uk.invalid> wrote:

>On Tue, 05 Jan 2016 20:13:17 +0100, Thomas 'PointedEars' Lahn
><PointedEars@web.de> wrote:
>
>>John Harris wrote:
>>
>>> On Mon, 04 Jan 2016 15:27:13 +0100, Thomas 'PointedEars' Lahn
>>> <PointedEars@web.de> wrote:
>>>> John Harris wrote:
>
> <snip>
>>>>> The syntax says
>>>>>   identifier_b = identifier_a ;
>>>>> The semantics are complicated. They say
>>>>>   If    The storage area associated with identifier_a holds a
>>>>>         primitive (non-object) value
>>>>>   Then  The storage area associated with identifier_b will now also
>>>>>         hold this primitive value, but a different instance of it
>>>>>   Else  The object associated with identifier_a will now also be
>>>>>         associated with identifier_b
>>>>>         (Note : there are other ways of saying this)
>>>>
>>>>How did you get that idea?
>>> 
>>> By reading ECMA 262.
>>
>>If you think that ECMA-262 (which Edition?) is confirming your ideas, then 
>>you will have no difficulty citing the corresponding algorithms and 
>>referring explicitly to the relevant parts.
>  <snip>
>
>Here are some extracts from ECMA-262, 6th Edition / June 2015, along
>with comments that explain how they justify what I wrote. The ...
>symbol in the extracts indicates that some irrelevant text has been
>omitted.
  <snip>

I wrote a description of a simple assignment. Thomas Lahn demanded
that I justify what I wrote. I wrote a justification. Now a month has
gone by and there are still no comments about it from Thomas.

Should I assume that Thomas realises that he was wrong, but is too shy
to say so?

Or should I assume that Thomas refuses to read my justification
because he believes he can't possibly be wrong?

  John

[toc] | [prev] | [next] | [standalone]


#29585

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2016-02-09 05:01 +0100
Message-ID<1683393.PAKbrVuEBG@PointedEars.de>
In reply to#29559
</killfile>

John Harris wrote:

> I wrote a description of a simple assignment. Thomas Lahn demanded
> that I justify what I wrote. I wrote a justification. Now a month has
> gone by and there are still no comments about it from Thomas.
> 
> Should I assume that Thomas realises that he was wrong, but is too shy
> to say so?
> 
> Or should I assume that Thomas refuses to read my justification
> because he believes he can't possibly be wrong?

Or perhaps your justifications are not worth the bytes that they take, and 
your postings are not worth replying to (as speedily as you would wish).  

Especially as you are obviously not actually interested in learning, let 
alone in an exchange of ideas.  *Everything* in your postings is Thomas 
here, Thomas there; you are apparently unable to separate the idea from the 
person having it; *everything* is a personal attack either against you or 
against people who have never asked you to fight for them in the first 
place.  And that makes it a PITA to have a discussion with you.

You might be retired already and have nothing else to do, but I do have 
other priorities in life than to correct all nonsense that all idiots post 
on the Net.  Especially if the nonsense exceeds a certain length.

Bottom line: Really sorry to break this to you, but you are *not* *that* 
*important* (to me).

Not reading your reply here,

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not cc me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#29587

FromJohn Harris <niam@jghnorth.org.uk.invalid>
Date2016-02-09 19:07 +0000
Message-ID<q6ekbb1mjk1l6j4irngdni491c46n61dd2@4ax.com>
In reply to#29585
On Tue, 09 Feb 2016 05:01:24 +0100, Thomas Lahn wrote:

></killfile>
>
>John Harris wrote:
>
>> I wrote a description of a simple assignment. Thomas Lahn demanded
>> that I justify what I wrote. I wrote a justification. Now a month has
>> gone by and there are still no comments about it from Thomas.
>> 
>> Should I assume that Thomas realises that he was wrong, but is too shy
>> to say so?

It looks as though the answer was : 

>> Or should I assume that Thomas refuses to read my justification
>> because he believes he can't possibly be wrong?
>
>Or perhaps your justifications are not worth the bytes that they take,
  <snip>


>Not reading your reply here,

Demanding proof and then not reading it is a cheap debating trick.


  John

[toc] | [prev] | [next] | [standalone]


#29588

FromJohn Harris <niam@jghnorth.org.uk.invalid>
Date2016-02-09 19:23 +0000
Message-ID<t2fkbb1oso57nntjcc9j6peuajrkl3u3cl@4ax.com>
In reply to#29585
On Tue, 09 Feb 2016 05:01:24 +0100, Thomas Lahn wrote:

  <snip>
>*Everything* in your postings is Thomas 
>here, Thomas there; 

Oh dear, I started this article by saying "Thomas Lahn wrote".


 <snip>
>I do have 
>other priorities in life than to correct all nonsense that all idiots post 
>on the Net.
  <snip>

So, ECMA 262 is nonsense. Quoting it proves nothing about ECMAScript.
Interesting.

  John

[toc] | [prev] | [next] | [standalone]


#29115

FromJoao Rodrigues <groups_jr-1@yahoo.com.br>
Date2016-01-03 04:26 -0800
Message-ID<039150a8-45c4-4708-8b73-484c81df2ca2@googlegroups.com>
In reply to#29105
Joao Rodrigues escreveu:
> On 01/01/2016 04:11 PM, Stefan Ram wrote:
> >    I define an object as follows (one line of input, one line
> >    of output from the firefox console):
> >
> > a = { length: 3 }
> > Object { length: 3 }


> >
> >    Now I observe the following three evaluations:
> >
> > a[ 0 ]
> > undefined
> >
> > a[ 1 ]
> > undefined
> >
> > a[ 2 ]
> > undefined
> 
> As noted above, "a" is an object, not an array. That's why you are 
> getting undefined whenever you try to access non existent properties of 
> the object. Try a['whatever'] for instance.

Try a['length'] or a.length and you'll get 3, because there is such property in the object.


> >    . So, is »a« now an »array-like object«, because it has
> >    a lenght between 0 and 9007199254740991 and it has three
> >    entries for the numeric keys 0 <= key < lenght, which
> >    just so happen to be »undefined«?
> >
> > b = Array.from( a )
> > Array [ undefined, undefined, undefined ]
> 
> Array.from() is supposed to be used with array-like or iterable objects 
> such as Map and Set. So you cannot pass non iterable objects such as 
> your "a".

In reality, Array.from() also accepts non iterable objects such as { length: 3 }, but the result can be tricky to understand, as Array.from() was designed to work with array-like or iterable objects

E.g. Array.from({g:50, t:20}) produces [].

> 
> When you write Array.from(a), I think JavaScript is creating an 
> array-like object with the length of 3 under the hood, so that the code 
> produces:
> 
> [ undefined, undefined, undefined ]
> 
> But I need to confirm that behaviour in the ECMA2015 Specification to be 
> sure.

I have confirmed that Array.from() is creating an array, following the steps of the ES6 Specification, section 22.1.2.1:
<http://ecma-international.org/ecma-262/6.0/index.html#sec-array.from>

Let's recap the example:

  var a = { length: 3 }
  Array.from(a) // [undefined, undefined, undefined]

Now, let's comment on the relevant steps of the Array.from()

22.1.2.1 - Array.from ( items [ , mapfn [ , thisArg ] ] )
[...]
Step 10 - Let len be ToLength(Get(arrayLike, "length")).

The abstract operation Get is used to retrieve the value of a specific property (P) of an object (O), as specified in section 7.3.1. So Get(O,P) will be Get(a,"length"), and we know that a.length returns 3.

  let len = toLength(a.length); // 3

Step 13 - Let A be ArrayCreate(len). The abstract operation ArrayCreate is defined in section 9.4.2.2.

  let A = new Array(len);

Step 15 - Let k be 0.
Step 16 - Repeat, while k < len. And following steps a thru h, we have something like:

  while (k < len) {
    v = items[k]; // v = a[k], so v = undefined.
    if (mapFn) {
       //
    } else {
      A[k] = v; // A[k] = undefined.
    }
    k = k + 1;
  }

Step 17 - Let setStatus be Set(A, "length", len, true).

Step 19 - Return A.

So, after all these steps, Array.from(a) will return the array
[undefined, undefined, undefined].

But if you write:

  var a = { length: 3 }
  Array.from(a, (value, key) => key);

FF and Chrome console will print out [0, 1, 2], instead of [undefined, undefined, undefined]


> >    So, the only thing we require for an object to be »array-like«
> >    is a length property with an appropriate value?
> 
> No, array-like objects must have:
> - indexed access to elements and the property length that tells us how 
> many elements the object has.
> - do not have array methods such as push(), forEach() and indexOf().
> 
> See:
> <http://www.2ality.com/2013/05/quirk-array-like-objects.html>
> 
 
For short, "array-like" objects have a length property and indexed elements.

-- 
Joao Rodrigues

[toc] | [prev] | [next] | [standalone]


#29118

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2016-01-03 16:54 +0100
Message-ID<1810599.sqNpoCiKvG@PointedEars.de>
In reply to#29115
Joao Rodrigues wrote:

> Joao Rodrigues escreveu:
>> Array.from() is supposed to be used with array-like or iterable objects
>> such as Map and Set. So you cannot pass non iterable objects such as
>> your "a".
> In reality, Array.from() also accepts non iterable objects such as {
> length: 3 }, but the result can be tricky to understand, as Array.from()
> was designed to work with array-like or iterable objects
> 
> E.g. Array.from({g:50, t:20}) produces [].

What is “tricky to understand” about this?  The object does not have a (non-
undefined) length property, so the length of the resulting array must be 0.

>> When you write Array.from(a), I think JavaScript is creating an
>> array-like object with the length of 3 under the hood, so that the code
>> produces:
>> 
>> [ undefined, undefined, undefined ]
>> 
>> But I need to confirm that behaviour in the ECMA2015 Specification to be
>> sure.
> 
> I have confirmed

… after I corrected you the day before …

> that Array.from() is creating an array

IOW, you have confirmed that you were wrong.  An Array instance is not an 
“array-like object” in the sense that you used the term.

> So, after all these steps, Array.from(a) will return the array
> [undefined, undefined, undefined].

You don’t say…

  /* [object Array] */
  ({}).toString.call(Array.from({length: 3}))

As can be seen in the Firefox console output *in the OP*.

> But if you write:
> 
>   var a = { length: 3 }
>   Array.from(a, (value, key) => key);
> 
> FF and Chrome console will print out [0, 1, 2], instead of [undefined,
> undefined, undefined]

Not surprising since you are mapping the “undefined”s of the property 
accesses …[0], …[1], and …[2] to their indexes 1, 2, and 3.  The above
can also be written

  Array.from(a, function (value, key) { return key; });

Incidentally, JSX has provided jsx.array.from() (for array-like objects) and 
jsx.array.fromObject() (for iterables) for several years before ECMAScript 
2015.

<http://PointedEars.de/wsvn/JSX?op=comp&compare[]=/trunk/object.js@392&compare[]=/trunk/object.js@393>
<http://PointedEars.de/wsvn/JSX?op=comp&compare[]=/trunk/@568&compare[]=/trunk/@569>

>> >    So, the only thing we require for an object to be »array-like«
>> >    is a length property with an appropriate value?
>> No, array-like objects must have:
>> - indexed access to elements and the property length that tells us how
>> many elements the object has.
>> - do not have array methods such as push(), forEach() and indexOf().
>> 
>> See:
>> <http://www.2ality.com/2013/05/quirk-array-like-objects.html>
>  
> For short, "array-like" objects have a length property and indexed
> elements.

You don’t say…
 
-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not cc me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#29127

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2016-01-04 00:18 +0100
Message-ID<18860206.z8ikl8hPK1@PointedEars.de>
In reply to#29118
Thomas 'PointedEars' Lahn wrote:

> Joao Rodrigues wrote:
>> But if you write:
>> 
>>   var a = { length: 3 }
>>   Array.from(a, (value, key) => key);
>> 
>> FF and Chrome console will print out [0, 1, 2], instead of [undefined,
>> undefined, undefined]
> 
> Not surprising since you are mapping the “undefined”s of the property
> accesses …[0], …[1], and …[2] to their indexes 1, 2, and 3.  The above

  accesses a[0], a[1], and a[2] to their indexes 0, 1, and 2.

> can also be written
> 
>   Array.from(a, function (value, key) { return key; });

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not cc me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.javascript


csiph-web