Assignment Expressions
The expression syntax, semantics, associativity
and precedence are quite identical to the corresponding C and C++ expressions except that the simple assignment operator in OQL is :=
instead of = in C or C++. The left operand must be a left value.
A left value is an OQL entity which is assignable: for instance any
identifier or a valid path expression.
When the assignment is simple and when the left value is an identifier,
no type checking on the right operand is done. For instance, x := 10
and x := "hello" are always valid expressions. In the case
of the left value is a path expression, the OQL interpreter checks that
the type of the second operand matches the expected type of the first one.
For instance if p denotes a Person instance,
p->age := 32 is certainly valid while p->age := "hello"
raises a type check error.
When the assignment is combined with another operation (for instance,
the -= operator), the left operand must be initialized and
the interpreter checks that the left and right
operand can be combined through the other operator.
For instance, the following constructs are valid:
a := 10;
a -= 20;
a := "hello";
a += " world";
p := first(select Person);
p.name := "johnny";
first(select Person.age = 0).name := "baby";
while these ones produce errors:
a := "hello";
a -= 20; // raises the error: operation 'string + integer' is not valid
a := list(1, 2);
a *= 2; // raises the error: operation 'list * integer' is not valid
unset b;
b += 20; // raises the error: uninitialized identifier 'b'
p := first(select Person);
p.age := "baby"; // raises the error: integer expected, got string
General Information |
Operators |
:= |
|
*= |
|
/= |
|
%= |
|
+= |
|
-= |
|
«= |
|
»= |
|
&= |
|
|= |
|
^= |
Type |
binary |
Syntaxes |
lvalue := expr |
|
lvalue *= expr |
|
lvalue /= expr |
|
lvalue %= expr |
|
lvalue += expr |
|
lvalue -= expr |
|
lvalue «= expr |
|
lvalue »= expr |
|
lvalue &= expr |
|
lvalue |= expr |
|
lvalue ^= expr |
Commutative |
no |
Operand Types |
leftvalue on the left side and any type
on the right side |
Result Type |
the type of the right operand |
Functions |
perform an operation and assignment |
Expression Examples |
expression |
result |
a := 24 |
24 |
a += 12 |
36 |
a /= 2 |
18 |
a ^= 100 |
118 |
first(select Person).age := 38 |
38 |
"hello" := 4 |
raises an error (i.e. "hello" is not a leftvalue) |
8 := 5 |
raises an error (i.e. 8 is not a leftvalue) |
unset a; a += 20 |
raises an error (i.e. uninitialized identifier) |
EyeDB manual