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

reuse choice expression in cases based on _result_ of match #3929

Open
michaellilltokiwa opened this issue Oct 14, 2024 · 0 comments
Open

reuse choice expression in cases based on _result_ of match #3929

michaellilltokiwa opened this issue Oct 14, 2024 · 0 comments
Labels
enhancement New feature or request Fuzion language related to the language, syntax, etc question A decision or information is required

Comments

@michaellilltokiwa
Copy link
Member

match ss.accept
             e error => e
             sock Java.java.net.Socket =>
               match sock.getInputStream
                 e error => e
                 i Java.java.io.InputStream =>
                   input  := jio.BufferedReader.new (jio.InputStreamReader.new i)
                   match sock.getOutputStream
                     ...

this could be written as:

match ss.accept as accepted
             error => accepted
             Java.java.net.Socket =>
               match accepted
                 error => accepted
                 Java.java.io.InputStream =>
                   input  := jio.BufferedReader.new (jio.InputStreamReader.new accepted)
                   match accepted.getOutputStream as os
                     ...

another example:

str option String := "Hello"
match str
   s String => s.substring 0 2
   nil => say nil

would be

str option String := "Hello"
match str
   String => str.substring 0 2
   nil => say str

The main advantage I see in this is that programmers would not have to introduce new names all the time.
Disadvantage could be that this could potentially be confusing in larger nested match expressions.

@michaellilltokiwa michaellilltokiwa added enhancement New feature or request question A decision or information is required Fuzion language related to the language, syntax, etc labels Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Fuzion language related to the language, syntax, etc question A decision or information is required
Projects
None yet
Development

No branches or pull requests

1 participant