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

Add match expression page #206

Closed
wants to merge 1 commit into from
Closed

Add match expression page #206

wants to merge 1 commit into from

Conversation

Girgias
Copy link
Member

@Girgias Girgias commented Nov 20, 2020

This is a W.I.P. any helped appreciated, especially @iluuu1994 for reviewing.

I'm struggling to describe some of the features and how to go about it, some of the terminology is copied from the Rust documentation: https://doc.rust-lang.org/reference/expressions/match-expr.html

@Crell
Copy link
Contributor

Crell commented Nov 20, 2020

Still missing, IMO:

  • Description of what is thrown if no expression matches.
  • You may want to explicitly call out the need for the closing semicolon. I don't know what conventions are on that, but it's not obvious for people used to } not needing a semicolon.
  • Explicitly state how compound arms work. It's implied, but not stated explicitly. Let's be explicit.

Recommended: A comparison with ternaries, not just switch. I've been saying since day 1 that match is more akin to a multi-armed ternary than it is to a switch statement. 😄

Optional: Note that if more complex checks than === are needed, match (true) {} can handle those cases.

@Girgias
Copy link
Member Author

Girgias commented Nov 20, 2020

Still missing, IMO:

* Explicitly state how compound arms work.  It's implied, but not stated explicitly.  Let's be explicit.

Don't really know how to write this up in all honesty.

Recommended: A comparison with ternaries, not just switch. I've been saying since day 1 that match is more akin to a multi-armed ternary than it is to a switch statement. 😄

I made a mention about it but I don't imagine that's what you want.

This includes:
 - match expression page
 - UnhandledMatchError page

Co-authored-by: Larry Garfield <larry@garfieldtech.com>
@Girgias Girgias changed the title [W.I.P.] Add match expression page Add match expression page Nov 22, 2020
Similarly to a <literal>switch</literal> statement, a
<literal>match</literal> expression has a subject expression that is
compared against multiple alternatives. Unlike <literal>switch</literal>,
it will evaluate to a value much like ternary expressions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it will evaluate to a value much like ternary expressions
it will evaluate to a value much like ternary expressions.

</listitem>
<listitem>
<simpara>
<literal>Match</literal> arms do not fallthrough compared to switch cases.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<literal>Match</literal> arms do not fallthrough compared to switch cases.
<literal>Match</literal> arms do not fall-through to later cases the way <literal>switch</literal> statements do.

@Girgias
Copy link
Member Author

Girgias commented Nov 22, 2020

@Girgias Girgias closed this Nov 22, 2020
@Girgias Girgias deleted the match-page branch November 22, 2020 17:31
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.

None yet

3 participants