Wanted: standard Array function to append an array's elements to another array

Andrea Giammarchi andrea.giammarchi at gmail.com
Sun Jul 31 03:57:21 PDT 2011


I agree mine is more a workaround while we need a solution but it's not
about Array here, it's about number of arguments limit per function so once
we have pushAll in place, all other methods will still suffer the "apply"
problem and it's not about apply either, e.g.

var tooMany = Array(0xFFFF).join(",$").replace(
    /,\$/g,
    function (m,i) {return m + i}
).slice(1);

alert(Function(
    tooMany,
    "return [" + tooMany + "].length"
)());

Too many parameters in function definition (only 32766 allowed)

So ... this is bad


On Sat, Jul 30, 2011 at 12:10 AM, Jeff Walden <jwalden+es at mit.edu> wrote:

> On 07/29/2011 05:22 AM, Andrea Giammarchi wrote:
>
>> to avoid apply limits is actually trivial
>>
>
> More or less, yes.
>
> But it requires the developer to anticipate the concern in advance that the
> elements being appended might consume all available stack space.  I don't
> think most developers think at all about the size of the stack, or about its
> being limited, except when they write a recursive algorithm, intentionally
> or inadvertently, and neglect to correctly implement the base case.  I
> certainly forgot about this concern when I wrote the buggy code which
> initially triggered this request, and I think it's reasonably apparent
> there's a problem when even a JS engine implementer makes this mistake.
>
> Past that, your MAX_LENGTH constant would have to be lower than the max
> length across all JS engines cared about.  I find it concerning that
> something as simple as extending an array with the elements of another array
> would require an implementation-dependent workaround, when this operation is
> built-in functionality in other mainstream languages where mutation is
> common:
>
> C++: vector<T>::insert
> http://www.cplusplus.com/**reference/stl/vector/insert/<http://www.cplusplus.com/reference/stl/vector/insert/>
>
> C#: List<T>.AddRange
> http://msdn.microsoft.com/en-**us/library/z883w3dc.aspx#Y570<http://msdn.microsoft.com/en-us/library/z883w3dc.aspx#Y570>
>
> Java: List<E>.addAll
> http://download.oracle.com/**javase/1.5.0/docs/api/java/**util/List.html<http://download.oracle.com/javase/1.5.0/docs/api/java/util/List.html>
>
> Perl: push
> http://perlmeme.org/howtos/**perlfunc/push_function.html<http://perlmeme.org/howtos/perlfunc/push_function.html>
>
> Python: list.extend
> http://docs.python.org/**tutorial/datastructures.html<http://docs.python.org/tutorial/datastructures.html>
>
> Ruby: array.concat
> http://www.ruby-doc.org/core/**classes/Array.html#M000224<http://www.ruby-doc.org/core/classes/Array.html#M000224>
>
> Jeff
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110731/67e791e8/attachment.html>


More information about the es-discuss mailing list