Hi,
I am trying to make a function that substitutes all the elements of an incoming list by a set of pairs of old and new elements.
incoming list: (1 2 3 1 2 2 1 3)
pairs of old and new elements: ((1 2)(2 3)(3 1))
=> (2 3 1 2 3 3 2 1)
It should not be able only swap the old and new elements, but also to substitute them
E.g ((1 2)(2 3)(3 4))
= (2 3 4 2 3 3 2 4)
and to substitute different old items by the same new item (and in reverse)
E.g. ((1 1)(2 1)(3 2))
=> (1 1 2 1 1 1 1 2)
It seems elementary, but when I tried to make it, it turns to be more complicated then I previously have been thinking.
[I was trying to make it by looping the substitute function (accumulation) and it works as long as the pairs of substitute items are of different types:
E.g. ((1 a)(2 b)(3 c))
=> (a b c a b b a c)
Yet, if the substitute pairs are numbers in the same range (or the ranges intersects), it can’t do the work!
Please, can you help me here?
Many greetings!
Aliser