More Matchers and Replacers
Null
The null element is written as () and represents nothing. When used as a matcher, it will match between any two symbols and at the start and end of every word.
This is most useful when used with environments to insert new symbols:
rule insert_a = () -> 'a' in 'b' _;This will insert an a after every b in the output, so bc will become bac and bb will become baba.
Null elements can also be used as replacers, in which case they will delete the match from the input word.
rule remove_a = 'a' -> ();This will remove all instances of a from the input, so ba becomes just b.
Wildcard
The wildcard matches any single symbol and is written .. It’s often used to write rules where the environment is what matters, or rules that skip symbols in environments.
rule oops_all_a = . -> 'a';This rule will replace all symbols in the word with a.
rule sad = . -> 's' in _ . 'd';This rule will replace any symbol with s if the symbol two places later is a d, so it will transform both bad and rad to sad.
Word Boundary
The # element matches the start or end of a word. If an input word contains spaces, this also applies to either side of the internal spaces.
rule variant1 = # -> 'a' in _ .;
rule variant2 = () -> 'a' in # _;Both of these rules do the same thing, adding an a at the beginning of words, in different ways. The variant1 rule replaces the word boundary with a if there is any symbol after it. The variant2 rule replaces a null (which, as explained above, matches on either side of any symbol) with a if there is a boundary on the left side of it.
Between Words
There is also a ## element, which matches on internal spaces. This can be used both as a matcher and a replacer to merge or split words.
rule merge = ## -> ();This will remove all word-internal spaces and merge two words into twowords
rule split = () -> ## in 'o' _ 'w';This will add a word-internal space wherever an o is followed by a w and transform twowords into two words.
Trying to use a space as a matcher such as ' ' in this case will not work, since spaces are removed in tadpole’s internal representation of words and replaced with special boundary markers.