This is the uniform state proposal by Kevin and Peter. We have discussed
this
propsal for a long time now. It is already implemnted in their local
branch.
I find this proposal to be the best compromise, and I suggest that it
should be immediately added
to the development version, with the intention that it becomes part of
the next release, after testing.
If there is any objection to putting it in the release we should vote on
that, but it should immediately go
to the development version.
-------- Seif
Uniform State Proposal
----------------------
We propose an extension to Oz to simplify the manipulation of mutable
entities. Mutable entities in Oz are cells, attributes, dictionary
elements, and array elements.
The motivation is to reconcile clean semantics, simple implementation,
convenient notation, and additional support for calculating with maps.
In the following, we consider that the notes concerning dictionaries
apply also to arrays.
THE MODEL
We add two new operators to the language, := and @. They operate on
mutable entities, i.e. cells, object attributes, and dictionary/key
pairs. A dictionary/key pair is just a tuple, e.g. D#K.
@E1 takes a mutable entity, the result of E1, and returns its current
value:
@a % attribute
@C % cell
@(D#K) % dict/key pair
This extends @'s current behaviour on object attributes to all mutable
entities.
E1 := E2 takes a mutable entity, the result of E1, and replaces its
contents with the result of E2:
a := foo
C := foo
D#K := foo
If E1 := E2 appears in an expression context then it provides atomic
exchange. The current contents of E1 are returned and then replaced
with the result of E2.
State Exchange
X = a := foo
X = C := foo
X = D#K := foo
Note that we don't introduce a new type for a dict/key pair. It is
just a tuple, so all tuple operations such as equality and selection
are valid for D#K.
SYNTACTIC EXTENSION FOR CALCULATING WITH MAPS
Oz has a number of data structures which may be used to hold mappings:
records, chunks, objects, and dictionaries (where the latter is a
mutable mapping).
* We extend the '.' operator to support mutable mappings. E1.E2
returns the value bound to key E2 in E1. This is the existing
behaviour (with Denys' extension to work for mutable mappings:
dictionaries and arrays).
* We add a new multifix operator '. :=', E1 . E2 := E3 requires E1 to
be a mutable mapping. It replaces the value bound to E2 in E1 with
the value of E3. Note that (E1.E2) := E3 isn't operator '. :='
because of the parenthesis. (E1.E2) := E3 is defined by the rules
for E1.E2 and :=.
Summarizing, if D is a dictionary then D.K := V is equivalent to
D#K := V and D.K is equivalent to @(D#K).
(This behaves almost identically to the existing implementation of '.'
support for Dictionarys. The only difference is that (D.K) := V is
currently identical to D.K := V)
This syntax also allows atomic exchange:
X = D.K := foo
SEMANTICS
We assume that the syntactic abstractions D.K := V and D.K are
translated to D#K := V and @(D#K) respectively.
Now we can define a translation of our extension to Oz.
@ E == case E of (D#K) then
{Dictionary.get D K}
elseif {IsCell E} then
{Access E}
else
{Obj.access self E} % Equiv to current @E
end
Note, @ already works for object attributes, we have used a dummy
routine Obj.access to describe the current behaviour of @.
If E is not a mutable entity then the routine will return a suitable
error.
E1 := E2 == case E1 of (D#K) then
{Dictionary.put D K E2}
elseif {IsCell E} then
{Assign E1 E2}
else
E1 <- E2
end
If E is not a mutable entity then the routine will return a suitable
error.
X = E1 := E2 == atomic
X = @E1
E1 := E2
end
where 'atomic ... end' is pseudo code indicating that the contents
must be implemented atomically.
-
Please send submissions to hackers@mozart-oz.org
and administriva mail to hackers-request@mozart-oz.org.
The Mozart Oz web site is at http://www.mozart-oz.org/.