robpike / ivy

ivy, an APL-like calculator
Other
1.33k stars 103 forks source link

iota is inconsistent about which index it returns when there are mulitple matches #118

Closed magical closed 1 year ago

magical commented 1 year ago

testcase.ivy:

"12301230" iota "1"
"12301230" iota "2"
"12301230" iota "3"
"12301230" iota "0"

I would expect this to print 1 2 3 4, but using the latest version (0.2.9) I get:

% ivy testcase.ivy
1
6
3
8

Using an earlier version of ivy, i see the expected results. (Not sure which version exactly, but it's about a year old)

% earlier/bin/ivy testcase.ivy
1
2
3
4
robpike commented 1 year ago

I could not reproduce this, but there was a non-stable sort, so I will change it to a stable sort and add a test. Please tell me if that fixes it.

robpike commented 1 year ago

Reopening until fix is confirmed

magical commented 1 year ago

Yep, that seems to fix it. Thanks!

If it helps, i built ivy with go1.17.6. I think the sorting algorithm has changed since then; that might be why you couldn't reproduce.

robpike commented 1 year ago

Yes, I think it has. A while back a similar issue in ivy was fixed the same way, but I missed this one.