Re: ES4 draft LAST CALL: Map

2008-03-21 Thread David Teller
I have a question related to collections in general.

I have the impression that ES4 will someday accept some kind of high-level 
concurrency, possibly Erlang-style. If so, we will probably need the ability to 
perform some kind of (destructive) pattern-matching/switch-type on the contents 
of a collection. Now, maybe this kind of pattern-matching will only needed for 
some concurrency-specific data structure, say a dynamically-typed Mailbox (à la 
Erlang) or a statically-typed Channel (à la Concurrent ML) or perhaps something 
higher-level (à la JoCaml).

With the current definition of Map and collections, this form of 
pattern-matching may probably be hand-coded using an iterator and 
intrinsic::remove, although the process is relatively unfriendly and the 
thread-safety will remain uncertain until there's a concurrency model for ES4.

Now, on to my question: should we add a method for finding some data in a 
collection from destructive pattern-matching or should this be left for later ?

Cheers,
   David

Quoting Lars Hansen [EMAIL PROTECTED]:

 Last call for comments.  Minor changes since previous drafts (and some
 comments at the beginning to address changes that are known to come).

 --lars




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


Re: ES4 draft LAST CALL: Map

2008-03-21 Thread Waldemar Horwat
The current definition in 1.2.2 of what Map(o) does is a harmful dead end.  The 
current behavior is:

- If o is already a Map then leave it alone.
- Otherwise enumerate the visible properties of o and construct a Map out of 
those.

This is harmful because it's guaranteed to cause current and future 
incompatibilities.  There are many other map-like things for which this is the 
wrong default and we'll be unable to fix them for compatibility reasons.  Here 
are just a few:

- If you construct a Map out of a Vector, you want the mapping of indices to 
the elements, with nothing else.  The default behavior brings in extraneous 
miscellaneous housekeeping properties (length, maybe fixed, perhaps more in the 
future).
- Folks will write libraries that define MultiMap and Set classes.  We'll want 
to later allow natural conversion of these to a Map, but the default will get 
in the way.

For these reasons the current definition of Map(o) is broken and should not be 
adopted.  The fix is to take out the auto-enumerating behavior.  If it's 
needed, it should be done by a static function.

Waldemar
___
Es4-discuss mailing list
Es4-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es4-discuss


ES4 draft LAST CALL: Map

2008-03-20 Thread Lars Hansen
Last call for comments.  Minor changes since previous drafts (and some
comments at the beginning to address changes that are known to come).

--lars
Title: The class "Map"




 The class Map 



NAME:   "The class 'Map'"
FILE:   spec/library/Map.html
CATEGORY:   Pre-defined classes (E262-3 Chapter 15)
SOURCES:REFERENCES [1], [2], [3]
SPEC AUTHOR:Lars
DRAFT STATUS:   LAST CALL - 2008-03-20
REVIEWED AGAINST ES3:   N/A
REVIEWED AGAINST ERRATA:N/A
REVIEWED AGAINST BASE DOC:  N/A
REVIEWED AGAINST PROPOSALS: YES
REVIEWED AGAINST CODE:  YES
REVIEWED AGAINST TICKETS:   YES
IMPLEMENTATION STATUS:  ES4 RI
TEST CASE STATUS:   Unknown


LAST CALL NOTES

  * (Tickets #247, #289, and e-mail discussion.) The meta::invoke
method will change when we change the meaning of statics in
parameterized classes.  Concrete types 'K' and 'V' will have to be
used in the invocation, and the returned 'Map' instance will be
from 'K' to 'V' instead of from 'EnumerableId' to '*', like this:

   Map.string,int( { x: 10, y: 20 } )

  * Should the WG adopt some proposal for default type parameters for
ES4 (not very likely) then the default values for 'K' and 'V' will
be 'EnumerableId' and '*'.

  * The WG has agreed that for a parameterized type Cls and type T,
Cls.T is a subtype of Cls.*.  That has yet to be
fully formalized, but it is used here.


CHANGES SINCE DRAFT 3 (2008-03-11)

  * The type previously known as 'function' is now known as 'Callable'

  * Cleaned out FIXME comments in the text.


CHANGES SINCE DRAFT 2 (2008-03-03)

  * The prototype 'get' and 'put' methods also accept a 'notfound'
parameter.

  * Presentation:
- section headers for intrinsic methods now use the syntax
  'intrinsic::foo()' instead of just 'foo'.
- compatibility note ("new in 4th edition")
- added an explicit "extends Object" clause.
- the informative method 'allElements' was renamed as 'allItems'.
- corrected a typo
- common fields in the status block above


CHANGES SINCE DRAFT 1 (2008-02-29)

  * The value returned by 'hashcode' is constrained to be a number and
is always explicitly converted to uint

  * Map(x) returns x if x is a Map

  * 'get' and 'put' have (V|undefined) return types

  * 'get' and 'put' accept an optional value (defaulting to undefined)
which is returned if the association was not found in the map

  * There is a new method 'clear' to clear the map

  * The object returned from helper::iterate has been annotated with
an explicit type, fixing the next field.


REFERENCES

[1] http:wiki.ecmascript.org/doku.php?id=proposals:dictionary
[2] http:bugs.ecmascript.org/ticket/146
[3] http:bugs.ecmascript.org/ticket/203



 The class Map is a parameterized, dynamic, non-final, direct
subclass of Object that provides a reliable, efficient, mutable,
and iterable map from keys to values.  Keys and values may be of
arbitrary types.

COMPATIBILITY NOTE  The class Map is new in the 4th Edition of this Standard.

 A Map is realized as a hash table.  When the Map is
constructed the caller may provide specialized functions that compare
keys and compute hash values for keys.

Synopsis

 The class Map provides the following interface:

__ES4__ dynamic class Map.K,V> extends Object
{
public function Map(equals:   Callable = (function(a,b) a === b),
hashcode: Callable = intrinsic::hashcode) 

static meta function invoke(object: Object=null): Map.EnumerableId,*> 
static public const length = 2;

intrinsic function size() : uint 
intrinsic function get(key: K, notfound: (V|undefined)=undefined) : (V|undefined) 
intrinsic function put(key: K, value: V, notfound: (V|undefined)=undefined) : (V|undefined) 
intrinsic function has(key:K) : boolean 
intrinsic function remove(key:K) : boolean 
intrinsic function clear() : void 

iterator function get(deep: boolean = false) : iterator::IteratorType.K> 
iterator function getKeys(deep: boolean = false) : iterator::IteratorType.K> 
iterator function getValues(deep: boolean = false) : iterator::IteratorType.V> 
iterator function getItems(deep: boolean = false) : iterator::IteratorType.[K,V]> 

private const equals   : Callable = 
private const hashcode : Callable = 
private var population : uint = 
}


 The Map prototype object provides these direct properties:

size:   function () 
get:function (key, notfound) 
put:function (key, value, notfound) 
has:function (key) 
remove: function (key) 
clear:  function () 



Methods on the Map class object

newMap.K,V(equals=,hashcode=)

Description  The Map constructor creates a new map for key type K
and value type V.

 The optional equals argument is a function that compares two
keys and returns true if they are equal and false if they are
not.