{action}
Runs one sequence action - reverse, sum, first and the rest - over a store, a range or a type, and iterates the result.
Syntax
{action store, reverse} ... {/action}
{action reverse, store} ... {/action}
{action store, first=2} ... {/action}
{action sum, '31..40'} ... {/action}
{action:reverse store} ... {/action:reverse}
{action:shift store, 2} ... {/action:shift}
Parameters
-
values -
A stored sequence named bare, a range
'31..40', or a sequence type with its options (prime, rows=5). -
action -
The action:
reverse,sort,shuffle,sum,average,median,count,dedup,first=n,last=n,shift=n,pop=n, ... The two may come in either order; in the prefix form{action:shift store, 2}the tag names the action and a bare number is its value.
Description
{action primes, reverse} ... {/action} applies one of the sequence actions to a list and iterates what comes out, the current value in {$sequence}. The list is usually a store pushed earlier, but a range ({action sum, '31..40'}, 355) or a type with its options ({action:reverse prime, rows=5}, 11 7 5 3 2) works too. Store and action may be written in either order, and the prefix form names the action in the tag: {action:reverse primes}, {action:shift primes, 2}.
The actions are those of {sequence}: orderings (reverse, sort, shuffle), selections (first=n, last=n, element, slice), aggregates that leave a single value (sum, average, median, count, minimum, maximum) and dedup. An aggregate's value is also there under the action's name - {$sum}.
The store is read, not rewritten: after {action primes, reverse} the store still holds its original order - except for shift and pop, which take values out of it. To transform a store in place, use {resume}; to apply several actions and plays to a store at once, {pull}.
Examples
An action over a store
Reverse, the first two and the sum of a stored list - the store keeps its order.
{sequence '1..6', push='six'}
<p>reverse: {action six, reverse}{$sequence} {/action}</p>
<p>first=2: {action six, first=2}{$sequence} {/action}</p>
<p>sum: {action:sum six}{$sum}{/action:sum}</p>
<p>store: {pull six}{$sequence} {/pull}</p>
reverse: 6 5 4 3 2 1
first=2: 1 2
sum: 21
store: 1 2 3 4 5 6
Taking from the front
shift takes values out of the store - each shift starts where the last one ended.
{sequence '1..7', push='line'}
<p>{action:shift line, 3}{$sequence} {/action:shift}</p>
<p>{action:shift line, 3}{$sequence} {/action:shift}</p>
<p>Left: {pull line}{$sequence} {/pull}</p>
1 2 3
4 5 6
Left: 7
See also
- {pull} Iterates a stored sequence, optionally through plays and actions.
- {resume} Transforms the sequence pushed last, in place, through an action or a play.
- {sequence} Generates a range, a list or one of 80 mathematical sequences, and iterates its values.