otp icon indicating copy to clipboard operation
otp copied to clipboard

Make function application left associative so it can be chained

Open richcarl opened this issue 1 year ago • 2 comments

A point where Erlang has always broken the Principle of Least Astonishment is in function application. You would typically expect (particularly in a functional language) that if a function call returns another function, you can apply it directly by appending another set of arguments within parentheses, but in Erlang, you are also forced to put the first function call within an extra parenthesis, like so: (f(X))(Y), rather than the expected f(X)(Y). For example, (accessor(Path))(Thing). This can get tiresome when you're working with higher order functions, and sometimes actually obscures the fact that a function application is happening, due to the extra parentheses acting as camouflage.

The fix is easy, and since it has not been allowed before there is no existing code where this would change the meaning. It however required me to slightly refactor the remote_expr part of the grammar to fix conflicts. It turned out this could also easily be relaxed, so that you can write get_callback_module(State):callbackFunc(...) instead of the current (get_callback_module(State)):callbackFunc(...).

richcarl avatar Dec 19 '24 19:12 richcarl

CT Test Results

    3 files    419 suites   1h 13m 19s ⏱️ 2 936 tests 2 886 ✅ 50 💤 0 ❌ 8 126 runs  8 070 ✅ 56 💤 0 ❌

Results for commit 9af30eec.

:recycle: This comment has been updated with latest results.

To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass.

See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally.

Artifacts

// Erlang/OTP Github Action Bot

github-actions[bot] avatar Dec 19 '24 19:12 github-actions[bot]

hi @richcarl , could you include some tests? Thanks

kikofernandez avatar May 15 '25 13:05 kikofernandez

Thanks! Added to our daily builds.

bjorng avatar Nov 17 '25 05:11 bjorng