Skip to content

fix behavior of nth with default argument #294

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

Merged
merged 2 commits into from
Mar 11, 2025

Conversation

phtrivier
Copy link
Contributor

@phtrivier phtrivier commented Mar 7, 2025

Closes #275

@frenchy64:

  • I tried adding a unit test, and I added some other test cases. I don't know if there is already a "compatibility" test for all this core clojure stuff ?

Note that tests where not all passing on my machine, so I had to run it as /bin/test -tc=nth

  • I don't know if the naming is proper for the test

  • I don't know if there is a formater, etc...

@frenchy64 frenchy64 self-requested a review March 7, 2025 22:52
Copy link
Contributor

@frenchy64 frenchy64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the unit tests, they're in a separate repo that aspires to be a common base of tests for all Clojure distributions. Tests for core functions won't be accepted here.

Instead, add your tests here https://github.com/jank-lang/clojure-test-suite/blob/main/test/clojure/core_test/nth.cljc and make sure they at least work in clj/cljs.

Then remove them from this PR.

We're in an unfortunate period where the unit tests for nth don't yet work in jank, as documented here.

So please manually try them with jank repl and paste the results in the PR.

In terms of the change, it looks good to me. Could you make the diff a single line, just the return statement without ws changes or tests?

There is a formatter, but it shouldn't bother this PR. I use git clang-format main to fix up my formatting.

@frenchy64
Copy link
Contributor

Could you also add Closes #275 in the PR description so merging this PR closes the issue?

@phtrivier phtrivier force-pushed the nth-inconsistency-in-default-case branch from 400591e to ceecbaf Compare March 8, 2025 10:11
@phtrivier
Copy link
Contributor Author

phtrivier commented Mar 8, 2025

Added tests in nth.cljc would look like this:

;; `nth` accepts a default argument
  (is (= :default (nth nil 0 :default)))
  (is (= :default (nth [0] 1 :default)))
  (is (= :default (nth [0 1] 2 :default)))

They pass when running lein test in jank/compiler+runtime/test/bash/clojure-test-suite/clojure-test-suite

Ran 124 tests containing 2949 assertions.
0 failures, 0 errors.

I've added them in the subrepo in another PR : jank-lang/clojure-test-suite#82

Copy link
Contributor

@frenchy64 frenchy64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@frenchy64 frenchy64 requested a review from jeaye March 8, 2025 22:00
Copy link
Member

@jeaye jeaye left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick change! Please address the CI failure. It failed because the branch you changed is now identical to the branch above it, so they can be merged.

After making the change, please request another review.

@phtrivier phtrivier force-pushed the nth-inconsistency-in-default-case branch from 5bbc059 to 1603750 Compare March 9, 2025 21:53
@phtrivier phtrivier requested a review from jeaye March 9, 2025 21:54
@jeaye
Copy link
Member

jeaye commented Mar 10, 2025

Thanks for the ping. I don't see any changes, though. 🙃 Not going to trigger CI again, since it'll say the same thing.

Right now the code has this.

    if(index < 0)
    {
      return fallback;
    }
    else if(o == obj::nil::nil_const())
    {
      return fallback;
    }

Static analysis is complaining about these two branch bodies being identical, so we need to combine them.

    if(index < 0 || o == obj::nil::nil_const())
    {
      return fallback;
    }

@phtrivier
Copy link
Contributor Author

Oh, sorry, I misread your comment and I thought you were talking about git branches, not the conditional branches 🤦

I'll fix that, sorry again!

@phtrivier
Copy link
Contributor Author

I fixed the code, normally.

@jeaye jeaye merged commit f04683c into jank-lang:main Mar 11, 2025
7 checks passed
@jeaye
Copy link
Member

jeaye commented Mar 11, 2025

Thanks for the fix!

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

Successfully merging this pull request may close these issues.

nth on nil with fallback differs from Clojure
3 participants