twaddle

Clipboard

Twaddle implements a clipboard feature with the copy and paste functions. This allows the evaluated result of a block to be saved for later reuse. A block’s result is copied to a named clipboard with the copy function, which takes one mandatory argument:

[copy:<name>]{<block>}

name is the name of the clipboard to which the block’s result will be copied. The clipboard name can be freely chosen (in principle even using lookups or applying other functions to determine the actual clipboard name, although it’s beyond me why anybody would want to do that).

The copy function is a block function, and the clipboard will save the entire evaluated contents of the next block to be opened. The result is saved to the clipboard before applying other functions such as reverse which would modify the text. If it is desired to save the modified text, the copy function should be placed in an external block.

Edge-Cases and Restrictions

In principle clipboard items can contain, and be copied/pasted within, any Twaddle features, including other clipboard items. They cannot, however, contain themselves recursively. A clipboard item is copied at the end of the block defining it, and cannot be pasted until the block is closed.

The pattern is evaluated before copying, so even blocks containing lookups and branching will produce the same output each time. If this is not desired, use saved patterns instead.

If the copy functions is called multiple times without opening a block to define the clipboard item, the next block will be copied under the name specified in the most recent copy call. The previous calls are ignored.

Note that while it is possible to copy a block at any point in a Twaddle sentence, blocks defined within branching paths will only be copied if the path defining them is chosen.

Difference from saved patterns

The clipboard may be easily confused with the saved patterns function. The difference lies in the fact that the clipboard saves the evaluated result of the following block, whereas patterns are saved before evaluation and are evaluated anew each time they occur.

Examples

>[copy:a]{hello} [paste:a]
hello hello

>[copy:a][reverse]{hello} [paste:a]
olleh hello

>[copy:a]{[reverse]{hello}} [paste:a]
olleh olleh

>[copy:a]{the <adj> <noun> <verb.ed>!} [paste:a] [case:upper][paste:a]
the electric buzzard strained! the electric buzzard strained! THE ELECTRIC BUZZARD STRAINED!