Re: `new Set()` or `new Map()` with more than one argument

2015-02-24 Thread Allen Wirfs-Brock

On Feb 24, 2015, at 5:52 AM, Axel Rauschmayer wrote:

 I’ve accidentally created the wrong set a few times:
 
 ```js
 let set = new Set('red', 'green', 'blue');
 // WRONG: same as new Set(['r', 'e', 'd'])
 ```
 
 Would it make sense to throw if either of the constructors `Set` and `Map` 
 receives more than one argument?

or perhaps we should have  Set.of(...args) and Set.from(iterable) methods.

Allen

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: `new Set()` or `new Map()` with more than one argument

2015-02-24 Thread Rick Waldron
On Tue Feb 24 2015 at 10:48:59 AM Allen Wirfs-Brock al...@wirfs-brock.com
wrote:


 On Feb 24, 2015, at 5:52 AM, Axel Rauschmayer wrote:

  I’ve accidentally created the wrong set a few times:
 
  ```js
  let set = new Set('red', 'green', 'blue');
  // WRONG: same as new Set(['r', 'e', 'd'])
  ```
 
  Would it make sense to throw if either of the constructors `Set` and
 `Map` receives more than one argument?

 or perhaps we should have  Set.of(...args) and Set.from(iterable) methods.


+1

Also, it occurs to me that specifying Set and Map to throw when there is
greater than 1 argument would provide insurance for the comparator function
argument. Sometime in the future, the operation could be relaxed to allow
accepting that second argument.

Rick
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: `new Set()` or `new Map()` with more than one argument

2015-02-24 Thread Mark S. Miller
As always with proposals to extend arity -- even if reserved by a thrown
error in a previous release -- how would you feature test for the extended
functionality?

I suspect the awkwardness of feature testing is one of the reasons why we
have not previously added new functionality by extending arity of existing
std functions. Though reserving by throwing does change the game somewhat.
Does it change the game enough?





On Tue, Feb 24, 2015 at 8:07 AM, Rick Waldron waldron.r...@gmail.com
wrote:



 On Tue Feb 24 2015 at 10:48:59 AM Allen Wirfs-Brock al...@wirfs-brock.com
 wrote:


 On Feb 24, 2015, at 5:52 AM, Axel Rauschmayer wrote:

  I’ve accidentally created the wrong set a few times:
 
  ```js
  let set = new Set('red', 'green', 'blue');
  // WRONG: same as new Set(['r', 'e', 'd'])
  ```
 
  Would it make sense to throw if either of the constructors `Set` and
 `Map` receives more than one argument?

 or perhaps we should have  Set.of(...args) and Set.from(iterable) methods.


 +1

 Also, it occurs to me that specifying Set and Map to throw when there is
 greater than 1 argument would provide insurance for the comparator function
 argument. Sometime in the future, the operation could be relaxed to allow
 accepting that second argument.

 Rick


 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss




-- 
Cheers,
--MarkM
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: `new Set()` or `new Map()` with more than one argument

2015-02-24 Thread Rick Waldron
On Tue Feb 24 2015 at 12:22:25 PM Mark S. Miller erig...@google.com wrote:

 As always with proposals to extend arity -- even if reserved by a thrown
 error in a previous release -- how would you feature test for the extended
 functionality?

 I suspect the awkwardness of feature testing is one of the reasons why we
 have not previously added new functionality by extending arity of existing
 std functions. Though reserving by throwing does change the game somewhat.
 Does it change the game enough?


TBH, I've never encountered the issue that Dr. Rauschmayer reported—so I'm
not convinced that it's necessary to do anything about it at all. I only
made the suggestion because I remembered the the user-defined comparator,
and figured that a thrown exception would prevent any code, that
accidentally relied on args  1 being silently ignored, from coming into
existence. So forget that, because you're right and this sucks:

  var m;
  try {
m = new Map(..., comparator);
  } catch (e) {
m = new Map(...);
  }

No thanks to that—I'd rather risk the rare cases in which args  1 are
silently ignored and bugs hopefully caught by well written tests.

Rick
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: `new Set()` or `new Map()` with more than one argument

2015-02-24 Thread Tab Atkins Jr.
On Tue, Feb 24, 2015 at 10:06 AM, Rick Waldron waldron.r...@gmail.com wrote:
 On Tue Feb 24 2015 at 12:22:25 PM Mark S. Miller erig...@google.com wrote:
 As always with proposals to extend arity -- even if reserved by a thrown
 error in a previous release -- how would you feature test for the extended
 functionality?

 I suspect the awkwardness of feature testing is one of the reasons why we
 have not previously added new functionality by extending arity of existing
 std functions. Though reserving by throwing does change the game somewhat.
 Does it change the game enough?

 TBH, I've never encountered the issue that Dr. Rauschmayer reported—so I'm
 not convinced that it's necessary to do anything about it at all.

Python has the same issue, and I've run into it before (exactly the
same examples - passing several strings, and unexpectedly getting a
Set of characters from the first string), but it's not too hard to
train yourself to always pass a list to Set.  I agree that we probably
don't need to do anything to fix this.

~TJ
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: `new Set()` or `new Map()` with more than one argument

2015-02-24 Thread Leon Arnott
or perhaps we should have  Set.of(...args) and Set.from(iterable) methods.

I was under the impression that Array.of() was solely an apologetic patch
over Array()'s broken arguments interpretation, and not really an apogee
for future or present collection classes.

Regarding the main topic: I personally this case would be better solved by
adding one of those Set and Map literal ideas that were [kicked around
awhile back](
https://mail.mozilla.org/pipermail/es-discuss/2014-October/039806.html) and
using those in lieu of the clunky constructor.
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss