[E-Lang] Immutable map operations

Tyler Close tclose@oilspace.com
Wed, 28 Mar 2001 19:56:20 +0100


MarkM wrote:
> Integers have this dual nature, as scalar and as
> collection.  For the
> operators that, in C, operate on integers, we should look
> at whether they
> apply to the integer as an arithmetic scalar vs as a
> bit-vector/set/collection in order to understand which
> extensions of their
> meanings might be more or less intuitive.  By this
> analysis, the arithmetic
> scalar oriented operators are:
>
>     binary: + - * / %   unary: -
>
> the arithmetic boolean operators are:
>
>     binary sort of: && ||   unary: !
>
> while the collection-oriented operators are
>
>     binary: & | ^ << >> unary: ~

I still like "+" for "add another element", but your analysis does
suggest another alternative.

The "<<" operator shifts another bit into the bit field / collection.
The "<<" operator has also already been overloaded by C++ to mean
"write". It therefore seems plausible that "<<" is the "add another
element" operator.

	? var q := [ 'a', 'b', 'c' ] toFIFO()
	# value: [a, b, c]

	? q <<= 'd'
	# value: [a, b, c, d]

Works well for maps too:

	map <<= (key, value)

">>" also seems plausible for "remove an element". The following would
remove one element equivalent to the given (key, value) pair.

	map >>= (key, value)

I think the real crux of this choice is what you decide to do with the
String+ operator. Does "+" append a single character?

	str += 'a'

Or:

	str <<= 'a'

Or:

	str |= [ 'a' ]

To my eyes, the first two seem acceptable, but the third is
ridiculous.

Tyler