11 Infix Notations

Oz supports infix and prefix notation for very common procedures (see Section 3.5 of ``The Oz Notation'').

In the following table, we give the prefix and infix notations and the corresponding expansions. The operators are grouped together according to their precedence. Members of the same group have the same precedence, groups further up have lower precedence than groups further down. ``Having higher precedence'' means ``binding tighter''; e. g., the term X.+ Z is equal to (X.Y) + Z. Ambiguities within each group are resolved by the associativity given before each group (e. g., - Y + Z is equivalent to (X - Y) + Z).

Infix

Normal

right-associative

X = Y

{Value.'=' X Y}

right-associative

+X := Y

Cell, Attribute, Dictionary or Array element assignment

Z = +X := Y

Cell, Attribute, Dictionary or Array element exchange

+C.+LI := X

Dictionary or Array element assignment

Y = +C.+LI := X

Dictionary or Array element exchange

+LI <- X

{Object.'<-' self LI X} %% Object.'<-' is internal

Y = +LI <- X

{Object.exchange self LI X Y} %% Object.exchange is internal

non-associative

?B = X == Y

{Value.'==' X Y B}

?B = X \= Y

{Value.'\\=' X Y B}

?B = +AFI1 < +AFI2

{Value.'<' AFI1 AFI2 B}

?B = +AFI1 =< +AFI2

{Value.'=<' AFI1 AFI2 B}

?B = +AFI1 > +AFI2

{Value.'>' AFI1 AFI2 B}

?B = +AFI1 >= +AFI2

{Value.'>=' AFI1 AFI2 B}

left-associative

?FI3 = +FI1 + +FI2

{Number.'+' FI1 FI2 FI3}

?FI3 = +FI1 - +FI2

{Number.'-' FI1 FI2 FI3}

left-associative

?FI3 = +FI1 * +FI2

{Number.'*' FI1 FI2 FI3}

?F3 = +F1 / +F2

{Float.'/' F1 F2 F3}

?I3 = +I1 div +I2

{Int.'div' I1 I2 I3}

?I3 = +I1 mod +I2

{Int.'mod' I1 I2 I3}

right-associative

+K, +R

{Object.',' K R}  %% Object.',' is internal

prefix

?FI1 = ~+FI2

{Number.'~' FI2 FI1}

left-associative

X = +Y.+LI

get content of Record, Dictionary, or Array element

prefix

X = @+Y

get content of Cell, Attribute, Dictionary or Array element

X = !!Y

{Value.'!!' X Y}

The expansion of the state-manipulation operators (., :=, and @) depends on the type of the expressions involved. The expansions are simplified, suitable error messages are returned if the type of the expressions are not valid.

E1.E2

E1.E2 expands to

if {Record.is E1} then {Value.'.' E1 E2} else @(E1#E2) end

returns the content of a record, dictionary, or array element.

E1.E2 := E3

E1.E2 := E3 expands to

@(E1#E2) := E3

'. :=' is a ternary operator for updating dictionary and array elements.

E1 := E2

E1 := E2 expands to

case E1  
of (D#K) andthen {Dictionary.is D} then {Dictionary.put D K E2}
[] (A#I) then {Array.put A I E2}  
elseif {IsCell E1} then 
   {Cell.assign E1 E2}
else 
   {Object.assign self E1 E2}   %% E1 <- E2 (Object.assign is internal)
end

':=' updates dictionaries, arrays, cells, and attributes. Note, Object.assign is a dummy routine and not actually visible to the library user.

@E

@E expands to

case E
of (D#K) andthen {Dictionary.is D} then {Dictionary.get D K}
[] (A#I) then {Array.get A I}  
elseif {IsCell E} then 
    {Cell.access E}
else 
    {Object.access self E}   %% @E (Object.access is internal)
end

'@' returns the current value stored in dictionaries, arrays, cells, and attributes. Note, Object.access is a dummy routine and not actually visible to the library user.

X = E1 := E2

X = E1 := E2 expands to

'atomic' 
   X = @E1
   E1 := E2
'end'

In an expression context ':=' performs an atomic exchange with the current value stored in the dictionary, array, cell, or attribute. Note 'atomic' ... 'end' is pseudo code to indicate that the exchange is an atomic action.


Denys Duchier, Leif Kornstaedt and Christian Schulte
Version 1.4.0 (20080702)