Hi Dave,

Apologies for the bad example. I tried to come up with a better and more 
meaningful example (Although maybe still not the best):

https://play.golang.org/p/MornIhiiZ9

Imagine I want to find all the combinations of four different type of coins 
that have a sum value less than or equal to 13 that always start with a 
coin value of 2. I know my code is probably not the best way to do that but 
let's say that's how we implement it. I have an initial slice of different 
possible combinations (Which is empty), and my initial combination (which 
includes coin of value 2).

My expectation is that the last and next to the last combination of the 
slice of combinations to be different always. Because I'm always adding a 
new element to the previous one (I'm removing the first combination from 
the slice of combinations, append a new type of coin to it, and then append 
the combination back to the slice).

Sorry if it is still not clear.

On Tuesday, December 19, 2017 at 2:26:14 PM UTC+11, Dave Cheney wrote:
>
> Hi There,
>
> At this stage of development it's unlikely to be a bug in Go's slice 
> implementation.
>
> I'd like to help but tbh your example is too long and I cannot follow what 
> it does let alone what it should do.
>
> Could you please do two thing for me; 
>
> 1. reduce the problem to the smallest possible case, which probably means 
> deleting all of the lines that do work as you expect, leaving only the line 
> which does not work.
> 2. write down in words, or in code, what you expected to happen.
>
> It should be straight forward to explain from there.
>
> Thanks
>
> Dave
>
> On Tuesday, 19 December 2017 14:03:47 UTC+11, Sasan Rose wrote:
>>
>> Please take a look at https://play.golang.org/p/BL4LUGk-lH
>>
>> I think I know how slices work (The 3-word structure). I tried to do my 
>> homework. But still I think I'm missing something here or it's really a bug.
>>
>> So In my code as you can see I'm appending to an slice (a variable called 
>> slice obviously) and removing from the beginning of it in a series of 
>> random operations (Actually it's not random it was happening in a loop but 
>> I tried to reproduce it this way). The problem is always at the last step 
>> (I separated each step by "=" signs) when I append to the array the (n-1)th 
>> element of array also changes to the appended value (This only happens when 
>> I create the appended value by appending an int to 'solutionNew' variable).
>>
>> Am I doing something wrong? Is this an intended behaviour? or is this 
>> really a bug? If I'm missing something I would be grateful if someone could 
>> explain it to me or share a reference with me so I can understand why this 
>> is happening. Thanks a lot.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to