Revision Notes for FRED 7.9

7.9.0

The following features were added in FRED version 7.9.0.

  • A new data type called list_table that has key-value pairs in which the value is a list. These will be global variables. Supporting functions include:

  • clear(list-table-name) - erase all key-value pairs

  • list-table-name[key-or-key-list] = <list-expression> - assign a list to one or more keys

  • <list-variable> = list-table-name[key] - get a list associated with a key

  • erase(list-table-name,key) - remove a list from the table

Other new functions:

  • sample_without_replacement(list-expression, k) - returns a random sample of the list of size k, without replacement

  • sample_with_replacement(list-expression, k) - returns a random sample of the list of size k, with replacement

  • select(list-expression, list-of-indexes) - returns the sub-list of the first argument corresponding to the list of indexes in the second argument.

  • select(list-expression, test) - returns the sub-list of the first argument consisting of the items that pass the test. The special variable _ in the test refers to the list item being evaluated. For example select(list(20, 5, 2, 40), (10 < _)) would return the list (20, 40).

  • select_index(list-expression, test) - returns the list of the indexes for the list in the first argument corresponding to items that pass the test. The special variable _ in the test refers to the list item being evaluated. For example select_index(list(20, 5, 2, 40), (10 < _)) would return the list (0, 3).

  • prev_state(condition-name) - return the agent’s previous state before transitioning to the current state. Note: previous transition may have been from the current state.

  • add(), sub(), mult() and div() all take list-valued arguments. If either or both argument is a list, the results is a list of values.

  • Updated documentation.

  • Bug fixes and efficiency improvements.

Notes

The parser translates X[string] to select(X,string), so the following are equivalent:

  • select(x_list, index_list) and x_list[index_list]

  • select(x_list, _>0) and x_list[_>0] : returns all positive numbers in x_list

  • select(x_list, ask(_,age)>18) and x_list[ask(_,age)>18] : returns the list of agents in x_list that have age > 18.