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

Support guards in maybe expression #7724

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

williamthome
Copy link
Contributor

This PR implements guards in maybe expressions.
The motivation for the PR is this topic by @josevalim in Erlang Forums.

Example

-module(maybe_guard).
-feature(maybe_expr, enable).
-export([t/1]).

t(X) ->
    maybe 
        Zero when Zero =:= 0 ?= X,
	One when One > 0, One < 2 ?= one(),
	ok
    else
	X -> {nonzero, X}
    end.

one() -> 1.
1> maybe_guard:t(0).
ok
2> maybe_guard:t(1).
{nonzero,1}

Notes

There are things to fix, but this PR is to start the discussion for the implementation of this feature.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 8, 2023

CT Test Results

       3 files     374 suites   53m 30s ⏱️
2 639 tests 2 578 ✔️ 59 💤 2
7 028 runs  6 965 ✔️ 62 💤 1

For more details on these failures, see this check.

Results for commit 3ce28b4.

♻️ 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

@jhogberg jhogberg added the team:LG Assigned to OTP language group label Oct 9, 2023
@kikofernandez kikofernandez self-assigned this Aug 12, 2024
@kikofernandez
Copy link
Contributor

Sorry for the delay, we will look into this in the coming week or so.
Thanks!

@williamthome
Copy link
Contributor Author

Hi, @kikofernandez.

No problem :)
I've not looked at this closely. This PR does not fully address the proposed.

Also, as mentioned in the Erlang Forum, this should be proposed in an EEP, and I agree to have things formalized. What do you or the OTP team think about this?

I can retake it or feel free to close this PR If the OTP team wants to assume this task.

@kikofernandez
Copy link
Contributor

I am not sure yet. I like being able to add guards, but maybe it also makes sense if we think this could be applied to assignments, as also suggested in the Erlang Forums...

I will run it internally and see if there are some catches that I may not see.
I will keep you posted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team:LG Assigned to OTP language group
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants