Atom - y - Translate

Characters: y

Tags: array

Arity: dyadic

This atom is dyadic, which means it takes two arguments.


Translate y based on the mapping defined by x.


x must be an even-length list. Each pair defines a mapping, and the mappings are applied in sequence. Then, the first list in each pair defines the source and the second list defines the destination. If the destination list is shorter, the last element is repeated as many times as needed.

For example, 5R 1,2,2,3y returns [3, 3, 3, 4, 5] because the 1 is mapped to a 2, and then both 2s are mapped to 3. However, 5R [1,2],[2,3]y returns [2, 3, 3, 4, 5] because there is only one mapping which is applied in parallel. Note that [a,b],[c,d]y maps a to c, not b. 10R [1,2,3],[4,5]y returns [4, 5, 5, 4, 5, 6, 7, 8, 9, 10] - the 1 maps to 4, the 2 maps to 5, and the 3 also maps to 5 because the destination list's last element is repeated if necessary.