_ (underscore)¶
Syntax¶
Description¶
Represents the current item in an evaluation expression.
Certain actions and functions in FRED and evaluated in pair-context, meaning
that the action refers to both the agent performing the action and one or more
other agents or values, called the other agent or value. In such actions or
functions, the special variable "_" is used as a place-holder representing
the other agent or value. When the action is evaluated, any occurrence of the
_ symbol is replaced with the other item.
Examples¶
The following code sets the personal list variable my_household_ages_list to the list of ages of members of the agent's household:
The action members(Household) returns a list of agent IDs. The action ask(_,age) returns the age of one agent in the list. The apply() action returns the list of values returned when ask(_,age) is evaluated for each agent in the list, Note that this example could also be accomplished by the following:
The next example creates a list with values twice that of the original list.
# After this code executes, y_list = list(2,4,6,8,10)
x_list = list(1,2,3,4,5)
y_list = apply(x_list, 2 * _)
The functions that set the variable "_" are:
apply(list-expression, pair-expression)
filter_agents(agent-list, pair-test1, ..., pair-testN)
index_agents(agent-list, pair-test1, ..., pair-testN)
The actions that set the variable "_" are: