Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assoc is broken #50

Open
esp1 opened this issue Feb 13, 2023 · 1 comment
Open

assoc is broken #50

esp1 opened this issue Feb 13, 2023 · 1 comment

Comments

@esp1
Copy link

esp1 commented Feb 13, 2023

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
Copy link
Author

esp1 commented Feb 13, 2023

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);
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant