Hoon, 34 bytes
|*(* `tape`(turn +< (cury mix 1)))
Stole Dennis' method for using char xor 1
to switch between '0' and '1'.
Return a gate that maps over the tape given, and calls (mix n 1)
(binary xor) for each element, then cast the resulting list back to a tape.
In Hoon, the entire memory model is a binary tree of bignums. All code is evaluated on this tree, called the 'subject'. +<
is "tree navigation syntax"; instead of specifying a name for the compiler to resolve into an axis of the subject, you can provide the axis yourself with alternating characters of +
/-
and <
/>
to walk the tree. Code within a gate is evaluated on a subject that has the arguments it was called with placed at +<
, so we can reference the arguments directly without having to assign a name to them.
|*
creates a wet gate, essentially a generic function, that is typechecked at the callsite with a monomorphized version of the gate. This lets us use *
as the sample for the gate instead of having to use |=(tape code)
- as long as the type of the arguments at the callee are a valid list, so that ++turn
typechecks.
> %. "10101110101010010100010001010110101001010"
|*(* `tape`(turn +< (cury mix 1)))
"01010001010101101011101110101001010110101"