Generalizing the E operator expansions

Tyler Close tjclose@yahoo.com
Sat, 26 Aug 2000 09:31:14 -0400


I've updated Hydro to support the partial order definitions that Markm
defined, as well as the hashtable equivalence behaviour that Dan
Bornstein suggested. The new version, Beta3, can be found at:
http://www.waterken.com/Hydro/2.0/

As Ken Kahn pointed out, and I can now testify is true, successfully,
and efficiently, pulling off the illusion that containers are
immutable is a tricky task. I think I've succeeded, but there are so
many possible permutations of use, that it's hard to know for sure at
this stage. I look forward to having some fresh fingers test it.

There are a few more things that need to be done in order to fully
integrate Hydro into E. One of those is operator support. The Hydro
containers now respond to the following E operators:

	< <= <=> >= > & | ^

I'd like E to support some other operators as well. Most of these
changes simply require renaming the method that the operator expands
to. I have tried to pick new names that are more general than the
current ones. Since E supports operator overloading by mapping to a
named method, it is important to have good, generally applicable names
for these operator expansion methods. Some of the current expansions
don't have generally applicable names.

Addition
--------
Create a container with an additional element.

	container + (element)

expands to:

	container with(element)

The current expansion method name is "add". To me, "add" implies that
the target will be modified. This is certainly not true of the
'primitive' types and is also not true for containers.

Subtraction
-----------
Create a container without an equivalent element.

	container - (element)

expands to:

	container without(element)

The current expansion method name is "subtract". Again, this method
name implies modification of the target.

Reverse
-------
Creates a container with the elements in reversed order.

	-container

expands to:

	container reversed()

The current expansion name is "negate". Not only does this method name
imply modification, but very few types have a notion of negation. On
the other hand "reversing" a number type could easily be construed to
be negation and will likely also have meaning for many other types.

Is empty?
---------
Checks if the container is empty.

	!container

expands to:

	container isEmpty()

The current expansion is "not". I think "not" probably has no meaning
outside of the boolean type. "isEmpty" would apply to a wide range of
types. For booleans, I think it is natural to think of false as being
empty and true being not empty.

Search
------
Get the value of the first element in a container that has an
equivalent key.

	container[key]

expands to:

	container search(key)

The current expansion is "get". I think "search" does a better job of
pointing out that there is a non-trivial runtime cost to the method.
"search" also does not indicate the existence of a "set".

Inversion
---------
Creates the inverse of an object.

	~object

expands to:

	object inverted()

The current expansion name is "complement". Not only does this method
name imply modification, but very few types have a notion of creating
a complemented version. More types have a notion of "inversion".
"inverting" an integer type could easily be construed to mean "one's
complement".

Difference
----------
Creates the difference between two containers.

	container_a & ~container_b

expands to:

	container_a mask(container_b)

E currently introduces a new operator for this operation, "&!". I
think the combination of "&" and "~" makes more sense. It would read
as "take the intersection of container_a with the container that has
all elements except those in container_b". This interpretation also
corresponds with the current behaviour of the integer type. "a & ~b"
masks the bits in a that are on in b.

Creating a new operator for this operation would be fine, but since E
has the smarts to combine operators, I think avoiding a new operator
makes sense in this case.

I think these operators should be sufficient to make container
manipulation, and manipulation of many other types, a pleasant task in
E.

Tyler Close, Founder Waterken Inc.
tyler@waterken.com
A35E 0621 44AD B616 DE29  F8DF 7B4C E859 71AB 47C5


__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://im.yahoo.com