8000 remove usage of method as function by Guest0x0 · Pull Request #2151 · moonbitlang/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

remove usage of method as function #2151

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
May 23, 2025
Merged

Conversation

Guest0x0
Copy link
Contributor

Previously, methods defined as fn f(self : T, ..) are considered both method and regular function. While this allows convenient ways of calling method via @pkg.meth(..), it also complicates the semantic of MoonBit.

The latest release of MoonBit now supports partial dot application (_.meth(..)) and piping into dot application (expr |> _.meth(..)), which significantly reduce the need for calling methods as regular functions. So we decided to deprecate the behavior of calling methods as regular functions, to simplify the language.

This PR removes usage of calling method as regular function in core. In next week's release, we will start emitting warnings on such usage. We are also simplifying the syntax of MoonBit's method system, the simplified syntax will also be available next week.

For most cases, this PR just migrates regular function apply to dot apply. However, for math related methods (Double::sin, for example), people are more used to function call style sin(..) from math notation, compared of dot apply style xx.sin(). So an fnalias is provided for math related functions and several others, such as Ref::swap.

@Guest0x0 Guest0x0 requested a review from bobzhang May 22, 2025 10:12 8000
Copy link
peter-jerry-ye-code-review bot commented May 22, 2025
Inconsistent handling of `sin`, `cos` and other math functions in string format

Category
Correctness
Code Snippet
pub fnalias Float::(sin, cos, tan, asin, acos, atan, atan2...)
Recommendation
Should extract common math functions into a separate shared list and reuse it between Float and Double
Reasoning
Mathematical functions are duplicated between Float and Double modules. Having them defined separately increases the risk of inconsistency and makes maintenance harder.

Missing documentation for the new `fnalias` syntax

Category
Maintainability
Code Snippet
pub fnalias Double::(sin, cos, tan...)
Recommendation
Add documentation explaining the fnalias syntax and its intended usage with examples
Reasoning
The new fnalias syntax is a significant language feature but lacks documentation about its purpose and proper usage, which could lead to confusion

Inconsistent patch style in test migrations

Category
Style Guide Complicance
Code Snippet
inspect(@double.is_nan(result), content="true") -> inspect(result.is_nan(), content="true")
Recommendation
Use consistent style for test migrations - either chain method calls or use temporary variables
Reasoning
The test migrations show inconsistent styles - some use method chaining while others use intermediate variables. A consistent style would improve readability.

@coveralls
Copy link
Collaborator
coveralls commented May 22, 2025

Pull Request Test Coverage Report for Build 6876

Details

  • 54 of 56 (96.43%) changed or added relevant lines in 9 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 92.451%

Changes Missing Coverage Covered Lines Changed/Added Lines %
immut/list/list.mbt 15 17 88.24%
Totals Coverage Status
Change from base Build 6872: 0.0%
Covered Lines: 8695
Relevant Lines: 9405

💛 - Coveralls

@bobzhang bobzhang enabled auto-merge (rebase) May 22, 2025 14:00
@Guest0x0 Guest0x0 force-pushed the Guest0x0/remove-method-as-func branch from 2cf7ec0 to 6e317b4 Compare May 23, 2025 02:43
@bobzhang bobzhang merged commit 2e52127 into main May 23, 2025
23 of 24 checks passed
@bobzhang bobzhang deleted the Guest0x0/remove-method-as-func branch May 23, 2025 02:59
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.

4 participants
0