y - Translate
This atom is dyadic, which means it takes two arguments.
y based on the mapping defined by
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.
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
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
10R [1,2,3],[4,5]y returns
[4, 5, 5, 4, 5, 6, 7, 8, 9, 10] - the
1 maps to
2 maps to
5, and the
3 also maps to
5 because the destination list's last element is repeated if necessary.