Skip to content

Structures

A structure field holds an ordered list of occurrences. Each occurrence carries the structure's member fields and an optional name, so one pets structure can hold several pets on the same person.

Reading a structure

Read a structure field like a list of occurrences, indexed from 0:

p is Person
COUNT(p.pets)           # number of occurrences
p.pets[0].name          # the name member of the first occurrence
p.pets[4] is known      # whether a fifth occurrence exists

Reading the field itself gives a list of dictionaries, one per occurrence, holding each member under its key and the occurrence name under __name:

PRETTY_PRINT(p.pets)

Assigning to a structure

Info

New in Atfinity 17.

Assign a list of dictionaries to a structure field. Each dictionary becomes one occurrence, in order:

p is Person
---
p.pets := [
  {"name": "Stiefel", "species": "good_dog"},
  {"name": "Bello", "species": "bad_dog"}
]
  • Assigning [] removes the occurrences the rule owns. An occurrence holding a value a user entered stays, with its rule-set members cleared; :=! removes it too.
  • The list is matched onto the existing occurrences in order rather than replacing them, so p.pets := [{}, {}, {}] leaves three empty occurrences, reusing any that were already there.
  • A member left out of a dictionary is set to not-given. A key that is not a member of the structure is ignored without warning, so a typo in a member key does nothing.
  • __name sets the occurrence's name.
  • The assignment does not enforce the structure's minimum or maximum number of occurrences. Assigning more occurrences than the Max Amount keeps all of them and marks the field with the same error a case shows when a lowered Max Amount leaves too many occurrences behind.

APPEND adds one occurrence and CONCAT joins a list of them, so you can extend a structure without restating it:

p.pets := APPEND(p.pets, {"name": "Hoppel", "species": "bunny"})

Set the name of a single occurrence directly:

p.pets[0].__name := "Favourite Pet"

The index can be a variable, which is evaluated when the rule runs:

last_index := COUNT(p.pets) - 1
p.pets[last_index].name := "Hoppel"

Values a user entered

Like any := assignment, this keeps any member or name a user has already entered, even when it updates an occurrence the assigned list reuses. Use the forced form :=! to overwrite them.