Re: {Weak|}{Map|Set}

2011-09-15 Thread Allen Wirfs-Brock
On Sep 14, 2011, at 9:42 PM, Kyle Simpson wrote: I too have been confused by the name weakmap...partially because the name is misleading, and partially because documentation on it is ambiguous/misleading. Specifically, weakmap really means weakkeymap, because only the key is weak, not the

Re: {Weak|}{Map|Set}

2011-09-15 Thread Kam Kasravi
The reference to private is actually in the Map, Set classes shown below. The BNF is also below: CallExpression : ... private ( AssignmentExpression ) ConstructorElement : ... PrivateVariableDefinition PrivateVariableDefinition : private ExportableDefinition class Map { private keys, vals;

Re: {Weak|}{Map|Set}

2011-09-15 Thread Mark S. Miller
On Wed, Sep 14, 2011 at 11:47 PM, Kam Kasravi kamkasr...@yahoo.com wrote: The reference to private is actually in the Map, Set classes shown below. Hi Kam, You're correct. Fixed now. Thanks for pointing it out. -- Cheers, --MarkM ___

Re: {Weak|}{Map|Set}

2011-09-15 Thread Brendan Eich
On Sep 14, 2011, at 11:09 PM, Allen Wirfs-Brock wrote: I would prefer ObjectMap (the keys are restricted to objects). Now that you point it out (again), I agree. People who know a bit about GC also confuse WeakMap with WeakRef/WeakPtr, which we have only in the strawman space:

Re: {Weak|}{Map|Set}

2011-09-15 Thread Andreas Rossberg
On 15 September 2011 09:10, Brendan Eich bren...@mozilla.com wrote: On Sep 14, 2011, at 11:09 PM, Allen Wirfs-Brock wrote: I would prefer ObjectMap (the keys are restricted to objects). Now that you point it out (again), I agree. I don't. :) It is true to some extent that WeakMap is GC

Re: {Weak|}{Map|Set}

2011-09-15 Thread Kyle Simpson
If I was a programmer looking for something like weak referencing in JS for the first time, weak is what I'd be searching for. But if you're actually aware of weakrefs (as I am), and you're searching for them in JS (as I was), and you see WeakMap (as I did), and you make the conclusion that

Re: {Weak|}{Map|Set}

2011-09-15 Thread Sean Eagan
Why constrain WeakMap to object keys, but not Map and Set ? I think it is because Weak only makes sense for object keys. However, if we base the distinction on iterability rather than weakness as David suggested, then we do not have to include an object key constraint anywhere. We could have:

Re: {Weak|}{Map|Set}

2011-09-15 Thread Mark S. Miller
Hi Kyle, It would be great if we found a name that suggested the full meaning of the abstraction by itself. WeakMap is certainly not that. Sometimes we find something like this. Also important is one that avoids suggesting any misunderstandings. I agree that ObjectMap beats WeakMap on those

Re: {Weak|}{Map|Set}

2011-09-15 Thread Allen Wirfs-Brock
On Sep 15, 2011, at 6:49 AM, Andreas Rossberg wrote: On 15 September 2011 09:10, Brendan Eich bren...@mozilla.com wrote: On Sep 14, 2011, at 11:09 PM, Allen Wirfs-Brock wrote: I would prefer ObjectMap (the keys are restricted to objects). Now that you point it out (again), I agree. I

Re: IDE support?

2011-09-15 Thread Andreas Rossberg
On 13 September 2011 16:48, Brendan Eich bren...@mozilla.com wrote: On Sep 13, 2011, at 5:33 AM, Andreas Rossberg wrote: * There are extra costs in space and time to doing the runtime analysis. * Compile time is runtime, so there are severe limits to how smart you can afford to get in a

Re: {Weak|}{Map|Set}

2011-09-15 Thread Mark S. Miller
On Thu, Sep 15, 2011 at 8:41 AM, Sean Eagan seaneag...@gmail.com wrote: Why constrain WeakMap to object keys, but not Map and Set ? I think it is because Weak only makes sense for object keys. However, if we base the distinction on iterability rather than weakness as David suggested, then

Re: IDE support?

2011-09-15 Thread Andreas Rossberg
On 13 September 2011 21:32, Wes Garland w...@page.ca wrote: When I write shell programs, and JS programs, I keep an extra terminal window open to a spare shell or a JS REPL.  I try stuff. Stuff that works, I copy into my program.  Then I run my program - which happens quickly, because the

Re: IDE support?

2011-09-15 Thread Andreas Rossberg
On 14 September 2011 00:00, Brendan Eich bren...@mozilla.com wrote: So, static+dynamic. The static side has some powerful algorithms to bring to bear. Dynamic is necessary due to eval and kin, and gives strictly more information (and more relevant information!). Nitpick: I believe you are

Re: {Weak|}{Map|Set}

2011-09-15 Thread Mark S. Miller
On Thu, Sep 15, 2011 at 8:47 AM, Allen Wirfs-Brock al...@wirfs-brock.comwrote: [...] No the normal use case for WeakMaps is simply to make associations between objects and arbitrary values. The special GC behavior is necessary to avoid memory leaks, but that is a quality of implementation

Re: {Weak|}{Map|Set}

2011-09-15 Thread Mark S. Miller
On Thu, Sep 15, 2011 at 8:41 AM, Sean Eagan seaneag...@gmail.com wrote: Also, for the iteration API of Map (i.e. IterableMap) and Set (i.e. IterableSet), why not integrate with iterators [1] : let m = new Map, s = new Set; ... for(i of m.iterator()) { ... } for(i of s.iterator()) {

Re: {Weak|}{Map|Set}

2011-09-15 Thread Andreas Rossberg
On 15 September 2011 17:47, Allen Wirfs-Brock al...@wirfs-brock.com wrote: No the normal use case for WeakMaps is simply to make associations between objects and arbitrary values.  The special GC behavior is necessary to avoid memory leaks, but that is a quality of implementation issue, not a

Re: {Weak|}{Map|Set}

2011-09-15 Thread Kyle Simpson
You say and you're searching for them in JS (as I was). Had the abstraction been called ObjectMap or ObjectRegistry, would you have found it? I don't think the API name is the only way someone can discover what they're looking for. Proper documentation for ObjectMap which said keyrefs are

Re: {Weak|}{Map|Set}

2011-09-15 Thread Allen Wirfs-Brock
On Sep 15, 2011, at 9:07 AM, Mark S. Miller wrote: On Thu, Sep 15, 2011 at 8:47 AM, Allen Wirfs-Brock al...@wirfs-brock.com wrote: [...] No the normal use case for WeakMaps is simply to make associations between objects and arbitrary values. The special GC behavior is necessary to avoid

WeakPair primitive ?

2011-09-15 Thread Sean Eagan
Would a WeakPair primitive be useful... let wp = new WeakPair(key, value); ... if(wp.hasKey(key)) { foo(wp.value()); } WeakMap could be built on top of this primitive: class WeakMap { constructor() { private pairs = new Set; private getPair = function(key) { for(i of

Re: WeakPair primitive ?

2011-09-15 Thread Allen Wirfs-Brock
On Sep 15, 2011, at 10:21 AM, Sean Eagan wrote: Would a WeakPair primitive be useful... let wp = new WeakPair(key, value); ... if(wp.hasKey(key)) { foo(wp.value()); } WeakMap could be built on top of this primitive: It's not that easy. Read

Re: IDE support?

2011-09-15 Thread Mike Shaver
On Thu, Sep 15, 2011 at 9:02 AM, Andreas Rossberg rossb...@google.com wrote: On 14 September 2011 00:00, Brendan Eich bren...@mozilla.com wrote: So, static+dynamic. The static side has some powerful algorithms to bring to bear. Dynamic is necessary due to eval and kin, and gives strictly more

Re: WeakPair primitive ?

2011-09-15 Thread Rick Waldron
WeakMap is in Harmony... http://wiki.ecmascript.org/doku.php?id=harmony:weak_maps On Thu, Sep 15, 2011 at 1:47 PM, Allen Wirfs-Brock al...@wirfs-brock.comwrote: On Sep 15, 2011, at 10:21 AM, Sean Eagan wrote: Would a WeakPair primitive be useful... let wp = new WeakPair(key, value); ...