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

Multi-expression matching support #140

Open
Lyrth opened this issue Nov 29, 2023 · 4 comments
Open

Multi-expression matching support #140

Lyrth opened this issue Nov 29, 2023 · 4 comments
Labels
enhancement New feature or request experimental The changes may break something or be a bad idea

Comments

@Lyrth
Copy link

Lyrth commented Nov 29, 2023

Would it be possible (and useful) to have match accept multiple expressions? Each match expression will match the corresponding case expression and evaluated as an and for each expression in a case.

local a, b = 2, 5
match a, b+1 {
  1,   a   => { print('no') }
  2,   4   => { print('neither') }
  b-1, 6   => { print('nay') }
  2,   a*3 => { print('THIS CASE will be selected') } 
}

If implemented, will probably be neater to have "passthrough" case expressions too, that technically works as a wildcard that always matches for that case expression, albeit it might be difficult to come up with a symbol (or existing keyword) for it.

@Markos-Th09
Copy link
Member

Markos-Th09 commented Nov 29, 2023

There is no case in clue. Also I am not sure how the b-1 and a*3 patterns would work, as they not supported anyways.

@Lyrth
Copy link
Author

Lyrth commented Nov 29, 2023

Oops, fixed that. Also unknowingly removed the print parentheses.

As for the latter concern, they do work and end up being if (_internal0 == b-1), etc. The precedence is another story, but in this case it's not a worry (yet)

@Markos-Th09
Copy link
Member

Oops, fixed that. Also unknowingly removed the print parentheses.

As for the latter concern, they do work and end up being if (_internal0 == b-1), etc. The precedence is another story, but in this case it's not a worry (yet)

this is if statement is basically unintended behavior, since b won’t be defined to what you would expect it to be?

@Maiori44
Copy link
Member

Maiori44 commented Nov 30, 2023

match branches can have any expression for its pattern, even if it's a useless/nonsensical expression

@Maiori44 Maiori44 added enhancement New feature or request experimental The changes may break something or be a bad idea labels Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request experimental The changes may break something or be a bad idea
Projects
None yet
Development

No branches or pull requests

3 participants