Spread and non objects

Mike Samuel mikesamuel at gmail.com
Fri Nov 5 08:16:28 PDT 2010

2010/11/5 Jon Zeppieri <jaz at bu.edu>:
> On Fri, Nov 5, 2010 at 8:14 AM, P T Withington <ptw at pobox.com> wrote:
>> [2p. from the Lisp world, the putative inventor of the rest/spread
>> operator.]
>> In Lisp, arglists are lists instead of arrays, the operator is `.`, and
>> conveniently, the empty list, `()`, and Lisp null, `NIL`, are just two ways
>> to write the same atom.  In Lisp, option B just falls out:
>>  (f . NIL) === (f . ()) === (f)
>> +1 for B as the best approximation (in the absence of a List data type).
> If the closest analogue of a Lispy list is an ESy array, then I think the
> empty array would be the best approximation.
>> We can't really have the symmetry that Zeppieri is looking for because you
>> want the rest operator to return an empty array when there are no rest args
>> (rather than null), so you don't need to test for null before manipulating a
>> rest arg.
> I can (finally) articulate my initial intuition (in favor of Erik's plan A).
> To the extent that the spread operator and rest args should be symmetrical,
> the following function should be an identity over its domain:
> function id(x) {
>   return (function(...x) { return x; })(...x);
> }
> But it can only be an identity when its argument is an array.

What do you think should happen with id(arguments)?
I tend to think it's best to launder arguments where possible to stop
the spread of unintended authority early.

    "There’s no obvious reason why ... should not work on any
    object with a length property and elements limited by length
    as ES5 Function.prototype.apply does."
would suggest
is equivalent to
   f("f", "o", "o")
so there's at least one non-object type that spread might decompose
though I don't know how this particular behavior for strings is

> Whether or not anyone else cares about this symmetry is another matter.
> Second issue: Erik suggests (plan B) that null and undefined are
> specifically special cased. I can't tell whether Brendan agrees with that or
> wants spread to be legal on any input whatsoever, because he writes that
> spread "should return an empty array on mismatch."

> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss

More information about the es-discuss mailing list