assoc is broken
esp1 opened this issue · 1 comments
esp1 commented
The expression (assoc {:a 1, :b 2, :c 3} :a 9))
should produce the result: {:a 9, :b 2, :c 3}
.
However in ferret this produces the result: {:a 9, :b 1, :c 2}
.
The :a
key is updated appropriately with the new value 9
, but the :b
and :c
keys are getting the shifted original values of :a
and :b
.
esp1 commented
I think the problem is in d_list::dissoc_aux
:
for_each(i, _keys) {
if (i == k)
continue;
new_keys = rt::cons(i, new_keys);
new_values = rt::cons(rt::first(_values), new_values);
_values = rt::rest(_values);
}
In the above loop if i == k
, the value should be discarded from _values
before continuing, e.g.:
for_each(i, _keys) {
if (i == k) {
_values = rt::rest(_values);
continue;
}
new_keys = rt::cons(i, new_keys);
new_values = rt::cons(rt::first(_values), new_values);
_values = rt::rest(_values);
}