On this page:
.
.
0.45+9.2.0.2

6.4 Dot🔗ℹ

expression

target_expr . id

 

expression

target_expr . id assign_op expr

 

repetition

target_repet . id

 

~order: member_access

 

assign_op

 = 

:=

 | 

:= ~cas old_expr ~to

 | 

other_assign_op

Accesses or updates a component of the value produced by target_expr, either statically or dynamically. The operation is static when target_expr is a dot provider. The access form also works as a repetition given a repetition for the target.

See also use_static.

> [1, 2, 3].length()

3

> class Posn(x, mutable y)

> def p = Posn(1, 2)

> p.x

1

> p.y := 20

> p

Posn(1, 20)

The := ~cas old_expr ~to assignment form is limited to a target_expr.id that statically refers to a mutable field of an object. It updates the field only when the current field value is === to the result of old_expr and only if the value can be atomically replaced with the result of expr. Otherwise, the current value is left intact. In this mode, the assignment expression produces a Boolean result: #true if the value was replaced, and #false if not. Beware that on some platforms, a “spurious” failure can produce a #false result and unchanged content even when the current content matches the result of old_expr. See also memory.order_acquire and memory.order_release.