Given a record, it is a common design pattern to update only a small number of its fields. Instead of forcing the programmer to copy the remaining, unchanged fields, CameLIGO offers a way to only update the fields that are modified.
One way to understand the update of records is the functional update. The idea is to have an expression whose value is the updated record.
Let us consider defining a function that translates three-dimensional points on a plane.
The syntax for the functional updates is:
It is important to understand that
phas not been changed by the functional update: a nameless new version of it has been created and returned.
JsLIGO does not support functional updates of nested records. For example, if you have the following record declarations:
You can update the record
user nested inside
account the long way:
Record types are comparable types, which means that their values can be implicitly compared for equality, and records can be used as keys in sets or maps. By default, the implicit, total order over records is undefined and implementation-dependent --- ultimately, the order is determined by the translated Michelson type.
When using the
@layout("comb") decorator, fields are translated in
Michelsom with their order as written in the source code, and records
are then ordered lexicographically (that is, when two fields of the
same name have the same values, another field is compared, much rather
like ordering two English words according to the alphabet).