{make}
Replaces every value of a sequence with what a sequence type makes of it.
Syntax
{make '1..5', add=10} ... {/make}
{make '1..5', add=10, multiply=2} ... {/make}
{make '1..6', prime} ... {/make}
{make:fibonacci rows=8} ... {/make:fibonacci}
{make store, square} ... {/make}
Parameters
-
values -
Where the values come from: a range
'1..5', a stored sequence named bare, or a sequence type to generate. -
type -
The sequence type applied to each value. An arithmetic type takes its operand as an option -
add=10,multiply=2,modulo=7; a type likeprimeorsquareturns n into its nth term.
Description
{make '1..5', add=10} runs a sequence in make mode: every value is replaced by what the named type makes of it - here 11 12 13 14 15. The arithmetic types take their operand as the option's value (add, subtract, multiply, divide, modulo, exponentiation, ...); other types turn a position into a term, so {make '1..6', prime} is the first six primes and {make '1..5', square} is 1 4 9 16 25. It is the same run as {sequence '1..5', make, add=10}.
Several makes apply in the order written: {make '1..5', add=10, multiply=2} adds first and doubles after, 22 24 26 28 30. A stored sequence named bare works as the source - the store itself is not changed; to rewrite it in place use {resume}.
Make is the default mode of a sequence run, so with only a type {make:fibonacci rows=8} simply generates that sequence, the same as {sequence fibonacci, rows=8}. Compare {keep}, {remove} and {flag}, the other three play modes.
Examples
Arithmetic on a range
One make, then two applied in the order written.
<p>add=10: {make '1..5', add=10}{$sequence} {/make}</p>
<p>add=10, multiply=2: {make '1..5', add=10, multiply=2}{$sequence} {/make}</p>
<p>modulo=3: {make '1..9', modulo=3}{$sequence} {/make}</p>
add=10: 11 12 13 14 15
add=10, multiply=2: 22 24 26 28 30
modulo=3: 1 2 0 1 2 0 1 2 0
Positions into terms
A type that computes terms turns each number n into its nth term.
<p>prime: {make '1..8', prime}{$sequence} {/make}</p>
<p>square: {make '1..8', square}{$sequence} {/make}</p>
<p>The default mode, with only a type: {make:fibonacci rows=8}{$sequence} {/make:fibonacci}</p>
prime: 2 3 5 7 11 13 17 19
square: 1 4 9 16 25 36 49 64
The default mode, with only a type: 0 1 1 2 3 5 8 13
See also
- {keep} Keeps only the values of a sequence that belong to a sequence type.
- {remove} Removes the values of a sequence that belong to a sequence type - the inverse of keep.
- {flag} Replaces every value of a sequence with 1 or 0: whether it belongs to a sequence type.
- {sequence} Generates a range, a list or one of 80 mathematical sequences, and iterates its values.
- {resume} Transforms the sequence pushed last, in place, through an action or a play.