How is this possible? What ought I check?
My recursive function visit(board) receives a struct, named incoming within the function.
nextBoard holds two slices left and right. Each slice contains small structs cell with components label1, label2 and bool.
Inside visit(incoming) I have:
nextBoard := advance(incoming)
savedInput := incoming
visit(nextBoard)
There are no other calls to visit inside it.
That is the background, now the problem: suppose at recursion depth 27 visit gets called, descending a further 12 levels. It then comes back to depth 27. Now incoming differs from its contents before that call. Oddly savedInput has changed too, in precisely the way incoming has. nextBoard still contains what it did before calling.
What I want to know is how? These 3 variables all have function scope, NOT scope at package level.
Some extra detail on incoming's changes: both left and right slices have len 7. Its right slice comes back with the 7th element changed from what it originally contained?
I do know that somewhere from depths 27 to 39, right's seventh element is replaced with left's seventh element, with its boolean reversed, and left loses its 7th element. A function named advance(incoming) performs that modification.
More precisely, when incoming comes back to depth 27, left is unchanged but right has the modification described above ie right[6]=left[6] with its boolean reversed.
My suspicion is that slices within slices still refer to memory shared with the original. It looks like the only reason incoming and savedInput would show identical modifications. Yet why would incoming differ at all after that call?
Thanks for taking the time to read this.
Is there a particular thing I should check? Am I misunderstanding the effect of writing savedInput:=incoming ? I've tried := as well as = with savedInput declared beforehand.