8000 refactor: replace letrec with let in non-recursive cases by FlyCloudC · Pull Request #2330 · moonbitlang/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

refactor: replace letrec with let in non-recursive cases #2330

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 1 commit into from
Jun 24, 2025

Conversation

FlyCloudC
Copy link
Contributor
@FlyCloudC FlyCloudC commented Jun 24, 2025

There are no letrec left in the core now.

Copy link
Changing from letrec to let may affect function recursion capabilities

Category
Correctness
Code Snippet

  • letrec sort_2 = fn(a : Int, b : Int) {
  • let sort_2 = fn(a : Int, b : Int) {
    Recommendation
    Verify that sort_2 and sort_3 don't need recursive capabilities before changing from letrec to let
    Reasoning
    The letrec keyword typically allows functions to refer to themselves in their definitions. While in this case the functions don't appear to be recursive, removing letrec could break functionality if there were any hidden recursive calls.
Duplicated code across multiple sort implementation files

Category
Maintainability
Code Snippet
sort_2 and sort_3 functions are identical across fixedarray_sort.mbt, fixedarray_sort_by.mbt, sort.mbt, and sort_by.mbt
Recommendation
Consider extracting these common utility functions into a shared module or using generics/traits to reduce code duplication
Reasoning
Having the same code duplicated across multiple files increases maintenance burden and risk of inconsistencies when changes are needed.

Lack of documentation for pivot selection logic

Category
Maintainability
Code Snippet
if len > use_median_of_medians {
sort_3(a - 1, a, a + 1)
sort_3(b - 1, b, b + 1)
Recommendation
Add comments explaining the pivot selection strategy and why specific positions are chosen for comparison
Reasoning
The pivot selection logic is complex and uses magic numbers (like 8 for minimum length). Documentation would help future maintainers understand the algorithm's strategy and constraints.

@coveralls
Copy link
Collaborator

Pull Request Test Coverage Report for Build 7482

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 89.343%

Totals Coverage Status
Change from base Build 7474: 0.0%
Covered Lines: 3521
Relevant Lines: 3941

💛 - Coveralls

@bobzhang bobzhang merged commit a9828f9 into moonbitlang:main Jun 24, 2025
16 checks passed
@FlyCloudC FlyCloudC deleted the remove-letrec branch July 2, 2025 10:48
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.

3 participants
0