set¶
Syntax¶
Parameters¶
x- A name of a variable, a list-variable or a table variable.
y- An expression with the same type as
x. index- An expression who value is treated as an index if
xis a list-variable an as a key ifxis a table variable. index-list- A list-expression who values are treated as a single compound key if
xis a table variable. value- A expression that evaluates to a numeric value.
Description¶
This action updates a variable, a list element, or one or more items in a table.
This is roughly equivalent to using the = sign as shown below, though you
should prefer to use the longform syntax when you have an index that isn't just
a simple variable or number and needs to be evaluated.
x = y # translates to set(x,y)
Some_list[index] = value # translates to set(Some_list, index, value)
Some_table[index] = value # translates to set(Some_table, index, value)
Some_table[index-list] = value # translates to set(Some_table, index-list, value)
A compiler error results if the type or number of arguments is not consistent with the type of the first argument.
Examples¶
my_y = x * 2
my_friend_list = some_list_of_agents
my_friend_list[10] = some_agent_id
my_lookup_table = some_other_table
my_lookup_table[some_agent_id] = ask(agent_id, age)
# this sets the value in the table with the compound key "list(id1, id2)" to 300
my_compound_key = list(id1, id2)
my_lookup_table[my_compound_key] = 300
Note
my_lookup_table[list(id1)] = 5 is equivalent to my_lookup_table[id1] = 5