On Nov 12, 2010, at 1:01 AM, Dmitry A. Soshnikov wrote:

> I consider several variants also. As Allen mentioned, if it will be a generic 
> thing, then `foo[-n]` may break an old code (and then we need another syntax 
> e.g. a[* - 1] -- if need at all then!). OTOH, if only for arrays -- I don't 
> see any big _real practical_ issues.

It is dangerous to make assertions based on wishes, instead of gathering data 
(see below).


>> that we should not just change indexing under Harmony script-type opt-in.
>> 
>> Note also that Python, at least, has a more elaborate system of slicing that 
>> has evolved over the years. I added slice in the Netscape 4 era, which made 
>> it into ES3 and has the desired negative index behavior, but other additions 
>> from that era (some from Perl!) do not match, and anyway, the 
>> array-index-is-a-property-name ship had sailed in 1995.
> 
> Of course it had sailed. But the thing is nobody (?) on that ship used 
> negative-array-index in old code -- in a some more-less serious _real 
> practical_ application.

You do keep asserting that. :-|


> Though, maybe nevertheless to completely port Python's slicing for arrays? ;P 
> I liked this idea. But -- only for arrays, not generic then. Unfortunatelly, 
> it may break current generic slice -- `[].slice.call({0:1, 1:2, length:2}, 
> -1)[0]` // 2.


>> Ruby does not dedicate syntax, using methods instead (Smalltalk-y, as one 
>> would hope).
> 
> How that? 

I was referring to slice.

Ok, data: I added logging code to detect whenever an array is accessed via a 
negative index to my custom http://hg.mozilla.org/tracemonkey Firefox build. 
Here after a few minutes of browsing is the  log file, piped through sort -u 
(there are many repeated entries):

file:///Users/brendaneich/Hacking/hg.mozilla.org/tracemonkey/OBJ/dist/MinefieldDebug.app/Contents/MacOS/components/nsSessionStore.js:1762:-1
http://i.i.com.com/cnwk.1d/html/rb/js/tron/oreo.moo.rb.combined.js:6:-1
http://i.zdnet.com/js/mootools-core-more.js:3:-1
http://l.yimg.com/a/combo?metro/tuc/tuc_outboxlite_0.0.29.js&metro/contentcarousel/contentcarousel_0.1.40.js&metro/contentcarousel/contentcarouseladserved_0.1.6.js&metro/uiplugins/toolbar_bridge_service_0.1.18.js&metro/uiplugins/tooltip_service_0.1.47.js&metro/uiplugins/sortable_service_0.1.20.js&metro/pa/pautil_0.1.4.js&metro/pa/palist_0.1.23.js&metro/pa/pa_0.1.218.js&metro2/multimedia/multimedia_0.0.6.js&metro/batchload/batchload_0.1.7.js:7:-1

I'll keep this browser running for a bit, but it is clear "somebody" used 
negative array indexes. And it would be no fun finding such dynamic occurrences 
when porting if we made negative indexes work as in Python in Harmony.

In general, taking ES5 strict code into Harmony should not require porting, 
other than removing any dependencies on global variable vs global object 
property aliasing.

/be

_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to