Aggregation

One of the powerful things that Collections_ allow is iteration and aggregation. Two keywords, “all”, and “any”, can be used with collection with varying results. Each element of the Collection_ will be assigned to a Variable_ that can be used in the final portion.

All

When the final portion of the all aggregation is a Boolean_, the all will also be a Boolean, constructing an AND over the individual elements.

(all [Collection] [Variable] [Boolean])

For example, the following is a Boolean_ that will be True if all players have a Hand size of zero.

1(all player 'P
2    (== (size ('P iloc HAND)) 0))

When the final element is a MultiAction_, the all will become a sequence over the actions, in order of the items in the collection.

(all [Collection] [Variable] [MultiAction])

We can see this in the following code to move each player’s top Trick card to the Discard pile.

1(all player 'P
2    (move (top ('P vloc TRICK))
3          (top (game vloc DISCARD))))

When the final element is a CardCollection, the all will become a CardCollectionCollection_.

(all [Collection] [Variable] [CardCollection])

This can be used to merge each player’s individual CardCollection_ elements, such as

1(union (all player 'P ('P vloc TRICK)))

When the final element is an Integer_, the all will become a sum of those Integer_ elements.

(all [Collection] [Variable] [Integer])

This is particularly useful for Integer_ storage locations which are part of an Owner_.

TODO FIND EXAMPLE!

Any

When the final portion of the any aggregation is a Boolean_, the any will also be a Boolean, constructing an ON over the individual elements.

(any [Collection] [Variable] [Boolean])

For example, the following is a Boolean_ that will be True if any player has Points greater than 10.

1(any player 'P
2    (> ('P sto POINTS) 10))

When the final element is a MultiAction_, the any will become a choice over the actions.

(any [Collection] [Variable] [MultiAction])

For example, the following is how a player can choose to play any Card_ in their Hand to the current Trick of a trick-taking game.

1(any ((current player) iloc HAND) 'AC
2    (move 'AC
3          (top ((current player) vloc TRICK))))