When to use makeMake is useful for complex sequence construction which is hard to express with sequence combinators and various combinations of utility words.
For example, this example uses
make and reads better than a version using utility words:
[ [ left>> , ] [ "+" % center>> % "-" % ] [ right>> , ] tri ] { } make
compare the above to
[ center>> "+" "-" surround ] [ left>> prefix ] [ right>> suffix ] tri
The first one has a similar shape to the eventual output array. The second one has an arbitrary structure and uses three different utilities. Furthermore, the second version also constructs two redundant intermediate sequences, and for longer sequences, this extra copying will outweigh any overhead
make has due to its use of a dynamic variable to store the sequence being built.
On the other hand, using
make instead of a single call to
surround is overkill. The below headings summarize the most important cases where other idioms are more appropriate than
make.
Make versus combinatorsSometimes, usages of
make are better expressed with
Sequence combinators. For example, instead of calling a combinator with a quotation which executes
, exactly once on each iteration, often a combinator encapsulating that specific idiom exists and can be used.
For example,
[ [ 42 * , ] each ] { } make
is equivalent to
[ 42 * ] map
and
[ [ reverse % ] each ] "" make
is equivalent to
[ reverse ] map concat
Utilities for simple make patternsSometimes, an existing word already implements a specific
make usage. For example,
prefix is equivalent to the following, with the added caveat that the below example always outputs an array:
[ , % ] { } make
The existing utility words can in some cases express intent better than a bunch of
, and
%.
Constructing quotationsSimple quotation construction can often be accomplished using
Fried quotations and
Compositional combinators.
For example,
[ 2 , , \ + , ] [ ] make
is better expressed as
'[ 2 _ + ]