[E-Lang] Immutable map operations
Tyler Close
tclose@oilspace.com
Fri, 23 Mar 2001 11:04:20 -0000
Dean wrote:
> This thread is to build some consensus on the core
> operations for immutable
> maps that should have syntactic support.
>
> The basic operations that might deserve syntactic support are:
>
> a) Retrieve: get a value based on a key
Yes.
> b) Variant: make a variant from an existing collection
> c) Update: update a variable with a variant
Despite arguments against it, I still think these two are related
through the "=" with "+" is "+=" syntax from C.
> d) Construct: make a new one
Yes.
> e) Accumulate: build a collection over time (e.g., in a loop)
This is the same as c).
> f) Iterate: both the keys and the values
Yes.
> g) Subset/split: This is a kind of variant that is a subset
> of the original.
I don't think this requires supporting syntax for maps. Sorted maps
are a different story. E currently only has unique maps, in which case
subset/split doesn't really have any useful meaning. Multimaps do have
a meaningful subset operation, but it probably doesn't require
supporting syntax.
> The above operations are not all the operations on a Map,
> merely the ones
> that I've seen and used good syntactic support for. Other
> operations that
> sometimes get syntactic support are count(), and more
> complex variant
> construction methods.
>
> Do people agree that these are the key operations for
> immutable maps? Did
> I miss any?
I have been dreading the impending discussion of "==" on collections.
All of the comparison operators ( < <= <=> >= > ) have meaningful
operations for maps.
All of the set operations ( | & ^ ~ ) have meaninful operations for
maps. Some of these are the same as your "b) Variant" operations. "|"
is the same as "withAll", "& ~" is the same as "withoutAll".
> The syntax to beat is message sending:
>
> Retrieve: map get(key)
map[key]
> Variant: map with(key, value)
map + (key, value)
> map withAll(map)
map | map
> map without(key)
map - key
> map withoutAll(keys)
map & ~map
> Update: map := map with(key, value)
map += (key, value)
> map := map withAll(map)
map |= map
> Construct: [k1 => v1, k2 => v2]
[ k1 => v1, k2 => v2 ] toMap()
> Accumulate: ???
map += (key, value)
> Iterate: for k => v in map { ... }
Yes.
> Subset: ???
No.
> I would
> note that the message passing approach has a lot to recommend it.
True. In my E pseudocode, the only ones I truly use a lot are, in
order: Construct, Iterate, Insert (subtype of Variant), Retrieve.
Tyler