Assignment
a := b
Local variable
Assigns value of expression b
to variable a
. Type of b
must be the same as (or compliant with) the type of a
.
All types are assignable, except ticket
For example:
var s = "a string";
s := "another string"
Tuple
Assigns a dimension of a tuple
variable.
For example:
var t = (2, "a string");
t[0] := 4;
t[1] := "another string";
/* t is (4, "another string") */
Record
Assigns a field value of a record
variable.
For example, consider the following record declaration:
record color {
red : bytes;
green : bytes;
blue : bytes
}
Then the following assigns the red
field:
var r = { red = 0xc6; green = 0x6d; blue = 0x32 };
r.red := 0xc8;
/* r is { red = 0xc8; green = 0x6d; blue = 0x32 } */
info
Other assignment operators below are also available for tuple dimension and record field.
a ?:= b : e
Assigns the some
value of option
b
argument to a
, and fails with e
otherwise.
For example:
var a : 0;
a ?:= unpack<nat>(0x0505) : "ERROR"
This is equivalent to:
var a = 0;
match unpack<nat>(0x0505) with
| some(v) -> a := v
| none -> fail("ERROR")
end
a += b
Increments variable
a
(local variable, tuple dimension or record field) by value of b
. It is equivalent to a := a + b
(see +
operator).Fails with
does not fail
a -= b
Decrements variable
a
(local variable, tuple dimension or record field) by value of b
. It is similar to a := a - b
(see -
operator). It is not exaclty equivalent because if may fail on nat
values (see fail conditions below).Fails with
"NAT_NEG_ASSIGN"
when
a
(typed nat
)is less than b
(typed nat
)."INVALID_NEGATIVE_TEZ"
when
a - b
value typed tez
is negative.a *= b
Multiplies variable
a
(local variable, tuple dimension or record field) by value of b
. It is equivalent to a := a * b
(see *
operator).Fails with
does not fail
a /= b
Divides variable
a
(local variable, tuple dimension or record field) by value of b
. It is equivalent to a := a / b
(see *
operator).Fails with
does not fail
a &= b
Fails with
does not fail