Re: decoupling [ ] and property access for collections

2011-11-03 Thread Waldemar Horwat
We had this in ES4, together with the provision that you could have multiple arguments between the [], so you could define data structures that can be addressed as: matrix2d[x, y] As in here, this would default to the ES5 semantics on objects that don't have the new [] proxy handler.

Re: decoupling [ ] and property access for collections

2011-10-20 Thread David Herman
[1] http://wiki.ecmascript.org/doku.php?id=strawman:dicts [D.H. already mentioned that this proposal does not reflect his current thinking, so beware] FWIW, I don't really know what my current thinking is. :) Dave ___ es-discuss mailing list

Re: decoupling [ ] and property access for collections

2011-10-19 Thread Axel Rauschmayer
Then we can continue to use . and [] to access properties and use @[] to access data structure elements. I wouldn’t like the asymmetry introduced by using [] for the latter task. this is plausible and certainly a way to avoid outrage about defining [ ]. I'll have to stew on it a bit to

Re: decoupling [ ] and property access for collections

2011-10-19 Thread John J Barton
On Wed, Oct 19, 2011 at 8:30 AM, Axel Rauschmayer a...@rauschma.de wrote: Then we can continue to use . and [] to access properties and use @[] to access data structure elements. I wouldn’t like the asymmetry introduced by using [] for the latter task. this is plausible and certainly a

Re: decoupling [ ] and property access for collections

2011-10-19 Thread Axel Rauschmayer
Thus, there really are two alternatives: 1. Changing [] in the above manner plus object@nameObject for accessing properties (as you suggested). 2. [] stays as it is and @[] (perhaps there is something slicker, e.g. .[]) is introduced for collections and dicts. Instead of creating a lot

Re: decoupling [ ] and property access for collections

2011-10-19 Thread John J Barton
On Wed, Oct 19, 2011 at 9:12 AM, Axel Rauschmayer a...@rauschma.de wrote: Thus, there really are two alternatives: 1. Changing [] in the above manner plus object@nameObject for accessing properties (as you suggested). 2. [] stays as it is and @[] (perhaps there is something slicker, e.g.

Re: decoupling [ ] and property access for collections

2011-10-19 Thread John J Barton
On Wed, Oct 19, 2011 at 9:52 AM, Axel Rauschmayer a...@rauschma.de wrote: What are you suggesting? A new primitive? Or a subtype of Object? I don’t think there is a third alternative to those two. I am suggesting that typeof return collection when the RHS defines a new semantic for []

Re: decoupling [ ] and property access for collections

2011-10-19 Thread Axel Rauschmayer
Problem: How do you invoke methods on table? table.tellAxel = function() {alert('here is a method call');}; table['tellAxel'] = function() {alert('here is a function entry);}; table.tellAxel(); // here is a method call table['tellAxel'].apply(null,[]); // here is a function entry

Re: decoupling [ ] and property access for collections

2011-10-19 Thread John J Barton
On Wed, Oct 19, 2011 at 10:27 AM, Axel Rauschmayer a...@rauschma.de wrote: Problem: How do you invoke methods on table? table.tellAxel = function() {alert('here is a method call');}; table['tellAxel'] = function() {alert('here is a function entry);}; table.tellAxel(); // here is a method

Re: decoupling [ ] and property access for collections

2011-10-19 Thread Axel Rauschmayer
So you are arguing in favor of approach #1, right? No, I am arguing against changing the meaning of [] on 'object'. Then I would make “your” Map a subtype of Object. typeof is currently best limited to primitives (and to distinguishing them from objects), so introducing a new result

Re: decoupling [ ] and property access for collections

2011-10-19 Thread Allen Wirfs-Brock
below On Oct 19, 2011, at 10:44 AM, John J Barton wrote: On Wed, Oct 19, 2011 at 10:27 AM, Axel Rauschmayer a...@rauschma.de wrote: Problem: How do you invoke methods on table? table.tellAxel = function() {alert('here is a method call');}; table['tellAxel'] = function() {alert('here is

Re: decoupling [ ] and property access for collections

2011-10-19 Thread Axel Rauschmayer
It isn't clear what you guys are arguing about. Under my proposal, old objects and old code operating upon old objects continue to work as it always has. new objects continue to work like old objects unless the new objects have been explicitly defined to have collection access behavior

Re: decoupling [ ] and property access for collections

2011-10-19 Thread Axel Rauschmayer
1. Deprecate [] for property access in non-collection objects and use methods such as Object.getProperty(name) and Object.setProperty(name, value), instead. Additionally: Object.prototype.operator[]get = function (name) { return Object.getProperty(name); } Object.prototype.operator[]set =

Re: decoupling [ ] and property access for collections

2011-10-19 Thread Allen Wirfs-Brock
On Oct 19, 2011, at 12:07 PM, Axel Rauschmayer wrote: 1. Deprecate [] for property access in non-collection objects and use methods such as Object.getProperty(name) and Object.setProperty(name, value), instead. Additionally: Object.prototype.operator[]get = function (name) {

Re: decoupling [ ] and property access for collections

2011-10-19 Thread John J Barton
On Wed, Oct 19, 2011 at 11:42 AM, Allen Wirfs-Brock al...@wirfs-brock.comwrote: below On Oct 19, 2011, at 10:44 AM, John J Barton wrote: On Wed, Oct 19, 2011 at 10:27 AM, Axel Rauschmayer a...@rauschma.dewrote: Problem: How do you invoke methods on table? table.tellAxel = function()

Re: decoupling [ ] and property access for collections

2011-10-19 Thread Axel Rauschmayer
In principal, that's how it should work. In practice, since we have to deal with objects that don't inherit from Object.prototype I suspect it is best to leave the fall back behavior as part of the definition of the operator. Cool. I don’t care how the details are handled, as long as there

decoupling [ ] and property access for collections

2011-10-17 Thread Allen Wirfs-Brock
ES objects and their properties have always had a dual nature. They can be used as both (semi-) fixed-shape object abstraction where the properties are the member names and they can be used as open ended data collections where property names are used as key values for accessing data in the

Re: decoupling [ ] and property access for collections

2011-10-17 Thread Dean Landolt
On Mon, Oct 17, 2011 at 4:30 PM, Allen Wirfs-Brock al...@wirfs-brock.comwrote: ES objects and their properties have always had a dual nature. They can be used as both (semi-) fixed-shape object abstraction where the properties are the member names and they can be used as open ended data

Re: decoupling [ ] and property access for collections

2011-10-17 Thread Erik Arvidsson
YES! This is the most exciting proposals I've seen in years. I'm so excited! With this we would be able to implement Array and all those pesky DOM collections without a hitch [*]. I think it might even allow sub classing Array if Array was reimlemented using this mechanism. [*] What of

Re: decoupling [ ] and property access for collections

2011-10-17 Thread Axel Rauschmayer
Dot access has always been nothing more than sugar -- a strict subset of the domain of legal property names. This subset excludes private names just as it excludes a whole range of strings, and for the same reason (insufficient syntax support). Arguing for syntax support is one thing -- and

Re: decoupling [ ] and property access for collections

2011-10-17 Thread David Herman
(Dave Herman has another way to say this: [ ] and . can be viewed as operating on two separate property name spaces, but for legacy/normal ES objects those namespaces are collapsed into a single shared namespace.) Lest the above be construed as a tacit approval on my part... ;) IMHO the

Re: decoupling [ ] and property access for collections

2011-10-17 Thread Axel Rauschmayer
- Pro: This conflation makes JavaScript very flexible. - Con: We only get poor man’s maps via objects. Most other dynamic languages (Python, Ruby, Groovy) allow any value as a key. - Con: Name collisions between map entries and properties is a constant source of trouble. For example, I

Re: decoupling [ ] and property access for collections

2011-10-17 Thread Allen Wirfs-Brock
On Oct 17, 2011, at 2:38 PM, Dean Landolt wrote: On Mon, Oct 17, 2011 at 4:30 PM, Allen Wirfs-Brock al...@wirfs-brock.com wrote: ES objects and their properties have always had a dual nature. They can be used as both (semi-) fixed-shape object abstraction where the properties are

Re: decoupling [ ] and property access for collections

2011-10-17 Thread Allen Wirfs-Brock
On Oct 17, 2011, at 3:34 PM, David Herman wrote: IMHO the single property name space of es-current is a feature, not a bug. I tend to agree. There are expressibility problems, too. For example, if you have an object that uses . for its API and [] for some other data, then what do you

Re: decoupling [ ] and property access for collections

2011-10-17 Thread Axel Rauschmayer
This would seem to be a fundamental conflict between using [ ] to access private properties and using [ ] as a special collection element accessor syntax. You might take this as problem with using [ ] as a collection accessor or as a discovering that using [ ] as a private property access

Re: decoupling [ ] and property access for collections

2011-10-17 Thread Axel Rauschmayer
I agree 100% percent with the observations, but not with the solution. Shouldn’t this be done the other way around, by introducing a new way of accessing map elements? For example: map@[key] map.[key] Then we can continue to use . and [] to access properties and use @[] to

Re: decoupling [ ] and property access for collections

2011-10-17 Thread Allen Wirfs-Brock
On Oct 17, 2011, at 3:32 PM, Erik Arvidsson wrote: YES! This is the most exciting proposals I've seen in years. I'm so excited! Thanks... What started me thinking along this line was noticing how Dart handles [ ] as a dynamically dispatched method. It isn't the first language to do so and C#

Re: decoupling [ ] and property access for collections

2011-10-17 Thread Allen Wirfs-Brock
On Oct 17, 2011, at 4:16 PM, Axel Rauschmayer wrote: I agree 100% percent with the observations, but not with the solution. Shouldn’t this be done the other way around, by introducing a new way of accessing map elements? For example: map@[key] map.[key] Then we can continue

Re: decoupling [ ] and property access for collections

2011-10-17 Thread David Herman
I suspect it's not nearly so rare as you think. For example, it just showed up in Tom and Mark's new proxy proposal: The protect trap is called on Object.{freeze,seal,preventExtensions}(aProxy). The operation argument is a string identifying the corresponding operation (“freeze”, “seal”,

Re: decoupling [ ] and property access for collections

2011-10-17 Thread Brendan Eich
On Oct 17, 2011, at 5:18 PM, David Herman wrote: I suspect it's not nearly so rare as you think. For example, it just showed up in Tom and Mark's new proxy proposal: The protect trap is called on Object.{freeze,seal,preventExtensions}(aProxy). The operation argument is a string

Re: decoupling [ ] and property access for collections

2011-10-17 Thread Allen Wirfs-Brock
On Oct 17, 2011, at 5:24 PM, Brendan Eich wrote: On Oct 17, 2011, at 5:18 PM, David Herman wrote: I suspect it's not nearly so rare as you think. For example, it just showed up in Tom and Mark's new proxy proposal: The protect trap is called on