You have two problems: The instead of as @nmichaels mentioned The function move/2 returns a list so the terminating clause must also return a list. This is not seen in your example as the first problem hides it So the resulting code would be: move(X|Xr, {Main, One, Two}) -> {Main, One, Two} | move(Xr, single(X, {Main, One, Two})); move(, {Main, One, Two}) -> {Main, One, Two} I flipped the order of the clauses as I personally prefer writing them this way. No fundamental difference in this case.
I am assuming that single/2 returns a tuple You can actually optimise this code by removing all knowledge of the tuple from move/2 as it never actually uses the internal structure. So: move(X|Xr, Tuple) -> Tuple | move(Xr, single(X, Tuple)); move(, Tuple) -> Tuple.
You have two problems: The | instead of , as @nmichaels mentioned. The function move/2 returns a list so the terminating clause must also return a list. This is not seen in your example as the first problem hides it.So the resulting code would be: move(X|Xr, {Main, One, Two}) -> {Main, One, Two} | move(Xr, single(X, {Main, One, Two})); move(, {Main, One, Two}) -> {Main, One, Two}.
I flipped the order of the clauses as I personally prefer writing them this way. No fundamental difference in this case. I am assuming that single/2 returns a tuple.
You can actually optimise this code by removing all knowledge of the tuple from move/2 as it never actually uses the internal structure. So: move(X|Xr, Tuple) -> Tuple | move(Xr, single(X, Tuple)); move(, Tuple) -> Tuple.
You want to use | instead of , when composing a list like that: move(X|Xr, {Main, One, Two}) -> {Main, One, Two} | move(Xr, single(X, {Main, One, Two})). The recursive call returns a list, which will just nest deeper and deeper unless you use | to flatten them out a bit. It's the same concept as in the pattern match X|Xr just with a reversed operation.
I tried that, but that will result in this, which is better, but not perfect: {a,b,,},{a,b,},{,b,a}|{b,,a} The '|' is still there in the answer. – Rickard Oct 31 at 14:50 @Rickard: Ah, right...what does single/2 do? – nmichaels Oct 31 at 14:51 It applies X to the lists Main, One and Two, and returns {MainX, OneX, TwoX}, a tuple with 3 lists.
– Rickard Oct 31 at 14:57 Solved it! I added an accumulator (I think), an empty list where I store the states instead of adding them on the way up from the recursion. Move(,Tuple, Y) -> append(Y,Tuple); move(X|Xr, Tuple, Y) -> move(Xr, single(X, Tuple), append(Y,Tuple)).
Is it correct to say that this is tail recursive? – Rickard Oct 31 at 15:20.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.